|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Something like this:
Code:
@array = []
parents = Parent.find(:all)
parents.each do |p|
kids = p.kids
kids.each do |k|
# Do something with the data
str = "#{p.id} #{p.parent_name} #{k.id} #{k.parent_id}"
@array << str
end
end
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > How to use ActiveRecord to retrieve all columns and rows... ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|