Rails 4: dynamic table name possible in `where` on` has_many: through`?

I have an association:

has_many :regions_deployed, -> { where(taggings: { scope: 'deployed' }) },
:through => :taggings, :source => :choice_filter, :source_type => "Region"

      

This usually works except when used in a joins

named scope clause that is bound to other named scopes that are also bound to taggings

. Postgres then aliases the table name taggings

, but where(taggings: { scope: 'deployed' }

does not reflect that alias. How to specify dynamic table name inside where

?

I think this question is closely related, but it can't get it: Including the same table twice with conditions

+3
ruby-on-rails associations arel


source to share


No one has answered this question yet

See similar questions:

15
Join twice on the same table with conditions

or similar:

346
Rails where condition using NOT NIL
51
Sphere with attachment: has_many: via union
13
Rails query join alias join table
nine
: enable and smooth the table
2
Static scale inside has_many in Rails 4
1
Scope of use in a query with a has_many relationship to the same STI table
1
How do you get Rails has_many through relationships to work with has_many conditions?
1
Rails 4 and parent id reference in 'has_many' SQL
1
ActiveRecord :: Relation cannot use named association in where the join clause
0
Get dynamic table alias in Rails scope



All Articles
Loading...
X
Show
Funny
Dev
Pics