P
Paul Vudmaska
I've got a few situations where i'm selecting a parent child
relationship with a join. I'm looking for an elegant way of iterating
through the children. Using the join, the parent table data is redundant
when there are muliple children.
for example, some pseudo code:
db.select_all('select * from parent,child where parent.id =
child.idParent') .each do |r|
if this_parent_id = old_parent_id
#must be a child, or first parent
paint_child
else
paint_new_parent
end
end
#or this.
db.select_all('select id from parent').each do |r|
paint_parent
db.select_all('select * from child where idParent = ?,r['id']).each
do |r|
paint_parent
end
end
Neither of these is elegant or efficient. Does anyone have a more ruby
way of working with a db parent/child relationship?
aul
relationship with a join. I'm looking for an elegant way of iterating
through the children. Using the join, the parent table data is redundant
when there are muliple children.
for example, some pseudo code:
db.select_all('select * from parent,child where parent.id =
child.idParent') .each do |r|
if this_parent_id = old_parent_id
#must be a child, or first parent
paint_child
else
paint_new_parent
end
end
#or this.
db.select_all('select id from parent').each do |r|
paint_parent
db.select_all('select * from child where idParent = ?,r['id']).each
do |r|
paint_parent
end
end
Neither of these is elegant or efficient. Does anyone have a more ruby
way of working with a db parent/child relationship?
aul