Last Updated: April 18, 2018
·
12.2K
· ernie

Nesting conditions in ActiveRecord

Rails 3.2.6 has caused some folks to experience regressions in their apps. It's usually because they were misusing nested conditions, before. It's true that joins/includes understand nested hashes of association references, but in the where clause, stock ActiveRecord doesn't assign any special importance to that nesting, and in fact, as of 3.2.6, actively prevents it. You should rewrite:

Model.joins(:other_models => :still_other_models).where(
  :other_models => {:still_other_models => {:attribute => 'value'}}
)

as:

Model.joins(:other_models => :still_other_models).where(
  :still_other_models => {:attribute => 'value'}
)