Relationship Proxies?

I’m trying to understand these results in irb, which implies that
there’s some kind of proxy at play:

aaron = User.find_by_login ‘aaron’
=> #<User:0xb7109cdc
@attributes={“salt”=>“7e3041ebc2fc05a40c60028e2c4901a81035d3cd”,
“updated_at”=>nil, “contact_info_id”=>nil,
“crypted_password”=>“00742970dc9e6319f8019fd54864d3ea740f04b1”,
“user_group_id”=>“10”, “remember_token_expires_at”=>nil, “id”=>“2”,
“disabled”=>“0”, “remember_token”=>nil, “locale”=>nil,
“login”=>“aaron”, “created_at”=>“2007-09-18 19:10:55”}>

og = aaron.user_group
=> #<UserGroup:0xb70ad3ec @attributes={“name”=>“FeedRoom Operations”,
“billing_contact_id”=>nil, “type”=>“UserGroup”, “contact_id”=>nil,
“id”=>“10”, “note”=>“Users with access to all client scopes.”,
“parent_id”=>“4”}, @original_language=nil>

og.name
=> “FeedRoom Operations”

sales = UserGroup.find_by_name ‘sales’
=> #<UserGroup:0xb709b5c0 @attributes={“name”=>“Sales”,
“billing_contact_id”=>nil, “type”=>“UserGroup”, “contact_id”=>nil,
“id”=>“5”, “note”=>“The sales team.”, “parent_id”=>“3”},
@original_language=nil>

sales.name
=> “Sales”

aaron.user_group = sales
=> #<UserGroup:0xb709b5c0 @attributes={“name”=>“Sales”,
“billing_contact_id”=>nil, “type”=>“UserGroup”, “contact_id”=>nil,
“id”=>“5”, “note”=>“The sales team.”, “parent_id”=>“3”},
@original_language=nil>

aaron.user_group.name
=> “Sales”

og.name
=> “Sales”

Can anyone point me to some reading material that explains why my
reference to a UserGroup model class changes when I alter the
refernence in the user from whence my reference came? It’s like
there’s some kind of proxy object in place that I can’t really see,
and I’d like to understand what’s going on.

Geoffrey W. wrote:

Can anyone point me to some reading material that explains why my
reference to a UserGroup model class changes when I alter the
refernence in the user from whence my reference came? It’s like
there’s some kind of proxy object in place that I can’t really see,
and I’d like to understand what’s going on.

There is an AssociationProxy under the covers, which allows you to add
stuff to the association. I don’t know of any specific docs for it.

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

mike

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs