Poking around books & blogs about association proxies, and experimenting, but I can''t seem to come across the right combination for this one particular task. I''m assuming there''s a way to get the "user_type" attribute from within the UserFilter using the belongs_to association? class PrivilegedUser < ActiveRecord::Base has_many :user_filters # has an attribute named user_type end class UserFilter < ActiveRecord::Base belongs_to :privileged_user def self.whatever x = self.privileged_user.user_type <------ ??? end end The example above gives me undefined method errors. -- gw --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-11 20:17 UTC
Re: Acquire parent attribute from child via belongs_to ?
On 11 Jun 2008, at 19:47, Greg Willits wrote:> > Poking around books & blogs about association proxies, and > experimenting, but I can''t seem to come across the right combination > for this one particular task. > > I''m assuming there''s a way to get the "user_type" attribute from > within the UserFilter using the belongs_to association? > > > class PrivilegedUser < ActiveRecord::Base > has_many :user_filters > # has an attribute named user_type > end > > class UserFilter < ActiveRecord::Base > > belongs_to :privileged_user > > def self.whatever > x = self.privileged_user.user_type <------ ??? > endThat can''t work - your whatever method is a class method, so self.privileged user is meaningless (since self is the class here). If whatever was an instance methood it should work as you''ve written it Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---