You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is basically that if I do a Parent.find(my_id) it will return the fully parsed object with parent and child attributes included, but if I declare a scope called foo on the Parent and define it as "where("type= ? and vendor_id = ?", @widget.type, @vendor.id)" and then call Parent.foo, it returns only the parents attributes.
It doesn't seem to say though what it is using instead so its hard to say where it needs to be overridden. I have a sinking suspicion that because each declared scope is instantiated as a method on the ActiveRecord class, you would have to override them individually, or at least force a call out of some sort to handle the override in a generic fashion.
Anyway, there is a workaround by doing Parent.find(:all, :conditions => "(type=#{@widget.type} and vendor_id=#{@vendor.id})") which seems to work just find. It just forces you to define the logic in each controller instead of obfuscating in the model.
Let me know if you have any ideas.
-Ryan
The text was updated successfully, but these errors were encountered:
I have a similar feeling that it may be necessary to override methods in ActiveRecord for functions utilising the database which is a bit of a nightmare.
So far I have been doing simple save/update functionality and so obviously it hasn't been an issue, perhaps there is some way in rails to intercept a scoped method or create something similar to the "before_save" function but for generic scopes?
The issue is basically that if I do a Parent.find(my_id) it will return the fully parsed object with parent and child attributes included, but if I declare a scope called foo on the Parent and define it as "where("type= ? and vendor_id = ?", @widget.type, @vendor.id)" and then call Parent.foo, it returns only the parents attributes.
APIDock acknowledges as much here: http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html
It doesn't seem to say though what it is using instead so its hard to say where it needs to be overridden. I have a sinking suspicion that because each declared scope is instantiated as a method on the ActiveRecord class, you would have to override them individually, or at least force a call out of some sort to handle the override in a generic fashion.
Anyway, there is a workaround by doing Parent.find(:all, :conditions => "(type=#{@widget.type} and vendor_id=#{@vendor.id})") which seems to work just find. It just forces you to define the logic in each controller instead of obfuscating in the model.
Let me know if you have any ideas.
-Ryan
The text was updated successfully, but these errors were encountered: