In Rails 3.2 this worked fine:
class Component < ActiveRecord::Base
has_and_belongs_to_many :brands
...
scope :branded, ->(b) { includes(:brands).where('brands.id in (?)', b.id) }
Other end of the relationship:
class Brand < ActiveRecord::Base
has_and_belongs_to_many :components
But I'm upgrading to Rails 4 and it breaks with this message:
Unknown column 'components.brand_ids' in 'where clause'
What's the problem here?
UPDATE
I haven't made the switch to strong parameters yet, and I'm using the protected_attributes
gem. Could that be the cause of all this?
IN
query for a singleid
? Just dowhere("brands.id = ?", b.id)
– Damien Rochehas_many
andbelongs_to
declaration of yourComponent
andBrand
models. Furthermore check that you run all pending migrations. – spickermann