Rails How to get all the grandchildren of an ojbect.

Posted by adam on Stack Overflow See other posts from Stack Overflow or by adam
Published on 2010-06-12T04:05:59Z Indexed on 2010/06/12 4:12 UTC
Read the original article Hit count: 372

Filed under:
|

I have 3 models

User
has_many :quetions
has_many :corrections
end

Question
has_one :correction
belongs_to :user
end

Correction
belongs_to :user
belongs_to :question

So if user Bob asks a question then user Terry can check it and if its wrong offer a correction.

Lets stay with bob and assume he as kindly corrected 5 other users, i.e and lets assume he has been lucky to get 3 corrections from other users.

I want to be able to do something like this

@bob.corrections_offered => 5 correction objects @bob.corrections_received => 3 correction objects

the first one is easy as its really just @bob.corrections under the hood. But i dont know how to implement the latter one. Can anyone help?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord