Arel table aliases and ActiveRecord::Relation help: how to specify "multiple has_many items in a que

What is the recommended way to use table aliases with
ActiveRecord::Relation these days?
In prior versions of Rails, this would work:

assume (pseudo code):
model A
has_many b’s

model B
,

at = B.arel_table
atalias = at.alias(at.name + “_1”)

A.join(:b).join(atalias).where(atalias[:a_id].eq(at[:a_id]).where(“b.widget
= ‘foo’”).where(“b_1.widget = ‘bar’”). …
^ probably should be “on”

now in 3.1.1: passing in a arel_table into join … returns a String,
not a relation, breaking the ActiveRecord::Relation chain.

In short: if we want to find A’s where they contain both a B.widget
‘foo’ and a B.widget ‘bar’ …
how do we do this without writing custom SQL ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs