在 Rails 3 中,我可以对关联模型执行查询:
示例 1:
model.associated_models.where(:attribute => 1)
associated_models 是一个模型数组。
是否可以对手动创建的模型数组执行 activerecord 查询?
示例 2:
[Model.create!(attribute: 1), Model.create!(attribute: 2)].where(:attribute => 1)
就像第一个示例中的 associated_models 和模型数组一样,但我想在调用 associated_models 时后台会发生一些事情。
我可以模拟这种行为以使示例 2 正常工作吗?