Hobo / hobo

The web app builder for Rails (moved from tablatom/hobo)

Home Page:http://hobocentral.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

belongs_to association with scope argument crashes hobo

stevemadere opened this issue · comments

Rails 4 allows (and indeed naggingly demands) that conditions on belongs_to
associations are specified with a scope lambda rather than a conditions option.
e.g.
belongs_to :pet, conditions: { breed: 'beagle'}, class_name: 'Dog'
must become
belongs_to :pet, -> { where(breed: 'beagle') }, class_name: 'Dog'

However, the various Hobo and HoboFields alias_method_chain actions on
belongs_to nail down the arguments to (name,options = {}).
This causes an argument count mismatch error at model load time.

Conversely, several wrapping of has_many include the scope lambda argument
for Rails 4 compatibility but are very confusing in a Rails 3 context. They only
work in Rails 3 by accident. (options actually go into a parameter called scope)

I am working on a pull request that will fix this and unite all such adaptations
for has_many and has_one as well with a consistent and robust solution using
variable parameters (*args)

Thanks Steve for the nice report, looking forward to your PR!