terry
2008-Feb-12 20:02 UTC
chaining objects in activeRecord, and accessing attributes from parent
Say I have Users table, and the user has many :items, if I define a method in the Item model say, def self.green so I can return all green items that belong to a user, I might use with_scope. fine, so I use like this: @user.items.green. But what if there is a preferences table so the user wants the items to be displayed in ascending order only, how would I access that from the def self.green method in the items model? So, I called @users.items.green, and I want to access user.preferences from the items model. Is this possible? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---