
June 25th, 2008, 10:20 PM
|
|
Contributing User
|
|
Join Date: Apr 2005
Posts: 321
  
Time spent in forums: 5 Days 18 h 21 m 47 sec
Reputation Power: 12
|
|
|
How to use ActiveRecord to retrieve all columns and rows... ?
Hi, how can i use ActiveRecord associations to retrieve all columns and rows including the columns and rows in the referenced table.
for example :
Code:
* = primary key
+ = foreign key
Table : parents
*id
parent_name
Table : kids
*id
+parent_id
kid_name
class Parent < ActiveRecord::Base
has_many :kids
end
class Kid < ActiveRecord::Base
belongs_to :parents
end
How can I get all the columns present in this two table and produce something like:
Code:
parents.id, parents.parent_name, kids.id, kids.parent_id, kids.kid_name
I only assume that the above ActiveRecord associations executes something like :
Code:
SELECT parents.id, parents.parent_name, kids.id, kids.parent_id, kids.kid_name
FROM parents left join kids on parents.id = kids.parent_id
Thanks
|