# Has a field through an association

**URL:** <https://www.ruby-forum.com/t/has-a-field-through-an-association/205921>\
**Category:** Rails\
**Created:** [April 18, 2011, 8:01pm UTC](https://www.ruby-forum.com/t/has-a-field-through-an-association/205921 "2011-04-18T20:01:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 18, 2011, 8:01pm UTC](https://www.ruby-forum.com/t/has-a-field-through-an-association/205921/1 "2011-04-18T20:01:20Z")

</div>

Hey guys,

Trying to figure out how to do something like the following:

class Child  
belongs\_to :parent  
has\_field :some\_field, :through =\> :parent  
end

class Parent  
has\_one :child  
attr\_accessible :some\_field  
end

child.some\_field #=\> parent.some\_field  
child.some\_field = value #=\> sets parent.some\_field = value

I can of course accomplish this by adding custom accessors to Child, but  
looking for a better solution. I could also write a plugin that  
dynamically adds the accessors, but not sure if something already  
exists.

Thanks in advance,  
Garrett L.

---

<div class="post-metadata">

**Author:** ![Garrett\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9f8e36/32.png) [@Garrett\_L](https://www.ruby-forum.com/u/Garrett_L)\
**Post date:** [April 19, 2011, 5:54pm UTC](https://www.ruby-forum.com/t/has-a-field-through-an-association/205921/2 "2011-04-19T17:54:09Z")

</div>

On Apr 18, 1:59pm, Garrett L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> has\_one :child  
> attr\_accessible :some\_field  
> end
> 
> child.some\_field #=\> parent.some\_field  
> child.some\_field = value #=\> sets parent.some\_field = value
> 
> I can of course accomplish this by adding custom accessors to Child, but  
> looking for a better solution. I could also write a plugin that  
> dynamically adds the accessors, but not sure if something already exists.

It sounds like you’re looking for something like delegate\_belongs\_to:

[https://github.com/faber/delegate\_belongs\_to](https://github.com/faber/delegate_belongs_to)

It does pretty much exactly what you’ve described.

–Matt J.
