# Relationship Proxies?

**URL:** <https://www.ruby-forum.com/t/relationship-proxies/115102>\
**Category:** Rails\
**Created:** [September 20, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/relationship-proxies/115102 "2007-09-20T16:28:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoffrey\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Geoffrey\_W](https://www.ruby-forum.com/u/Geoffrey_W)\
**Post date:** [September 20, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/relationship-proxies/115102/1 "2007-09-20T16:28:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Geoffrey\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Geoffrey\_W](https://www.ruby-forum.com/u/Geoffrey_W)\
**Post date:** [September 20, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/relationship-proxies/115102/2 "2007-09-20T17:22:26Z")

</div>

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.

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

mike
