Paul Jonathan Thompson
2006-Jun-16 01:45 UTC
[Rails] Nuby Question: How best to read a child record?
I want to read through all the child records for a given parent. What would be the correct way to do this? Advise would be most welcome. Regards, Paul
Josh Susser
2006-Jun-16 05:56 UTC
[Rails] Re: Nuby Question: How best to read a child record?
Paul Jonathan Thompson wrote:> I want to read through all the child records for a given parent. What > would be the correct way to do this? Advise would be most welcome.Use the collection method created by the association you use to define the relation to the child records. I assume you are using has_many. So if in class Parent you have "has_many :children" then "parent.children" returns a collection of the child objects. Give the docs a shot: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.