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.
On Apr 18, 1:59pm, Garrett L. [email protected]
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
It does pretty much exactly what you’ve described.
–Matt J.