hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Finders with hash attributes are not supported #36

Closed baldursson closed 10 years ago

baldursson commented 11 years ago

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.

hzamani commented 11 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?

mfoste commented 10 years ago

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})
hzamani commented 10 years ago

fixed in active_record-acts_as gem