Acquire parent attribute from child via belongs_to?

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

On 11 Jun 2008, at 19:47, Greg W. wrote:

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

That 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