Hello,
I have tried to tackle this one with some people on IRC, but the
proposed solution doesn't really satisfy me, as it solves the problem
only in a special case, and not in general.
So I have two models in my rails app, say Child and Parent, where the
Parent has_many :children and the Child belongs_to :parent. I have
attributes I want the Child to have that the Parent holds, some exist
as columns in the Child that if set override, some others that only
exist in the Parent. That is realised through custom getters defined
thus:
"""
%w{ some nifty attr_ibutes }.each do |attrib|
define_method attrib do
read_attribute("#{attrib}") || parent.send("#{attrib}")
end
end
"""
So far so good, and everything there works very well.
My problem here is that attributes the Parent has the Child doesn't
don't get included in stuff like .to_xml or even .attributes. In the
example at hand, if child has the column 'nifty' but not 'some' and
the parent has both, Child.find(0).attributes yields 'nifty' but not
'some', same for Child.find(0).to_xml and so on. Is there a way to
tell the Child model that even if the attributes are virtual, I want
some of them to behave like real ones?
Regards,
Felix
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---