Closed baldursson closed 10 years ago
When useign hash conditions you have to use association key to specify the model, something like this:
SubModel.find_or_create_by(supermode: {attribute: value})
And thats why find_or_create_by
don't work as well.
We may fix this (or at fix least find_or_create_by
) but as we go along things are getting more and more messy!
Are there any idea on how to get raid of this simulation, and have real multi-table-inheritance?
Going from Rails 4.0 to 4.1, I had to change from using the superclass singular association key name to using the plural superclass table name:
SubModel.where(supermodel: {attribute: value})
Changed to
SubModel.where(supermodels: {attribute: value})
fixed in active_record-acts_as
gem
This works: SubModel.where("attribute = ?", value)
This does not: SubModel.where(attribute: value)
And I guess that is also related to why this is not supported: SubModel.find_or_create_by(attribute: value)
It's not crucial, since there are workarounds, but it forces me to write my code in a way I wouldn't normally do. Hashes are simply more elegant.