x = Project.where(‘status=?’,‘active’).eager_load(:tasks)
but how do i access it? my loops are failing when tryin to access the
associates attribute:
x = Project.where(‘status=?’,‘active’).eager_load(:tasks)
x.each do |rec|
p rec.id #<< OK
p rec.tasks.id # << OUCH
end
pls advise
“OUCH”? What does that mean? You’ll generally get more useful
answers if you show an actual error message. And for that matter
googling that error will frequently give you pointers towards
solving
it yourself.
I would guess that “tasks” is a collection; do you expect that to
have an id? Or are you looking for the id of an individual task?
ok, if i do this then i can acces the associated records:
x = Project.where(‘status=?’,‘active’).eager_load(:tasks)
x.each do |rec|
p rec.id #<< OK
rec.tasks http://rec.tasks.id/ each do |y|
p y.id
end
end
i guess i was just expecting a flat table because thats what i saw in
the
mysql query result pane
thx again
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.