On Jun 14, 2:28 pm, "eric draut" <
edr...@gmail.com> wrote:
> an array of associations selects each array member and associates it with
> the parent model in a flat list fashion. A hash selects the associations in
> the key list of the hash, then finds the values as they associate to the
> key, not the model on which you are calling AR#find
>
> So:
>
> Student.find(:all, :include => {:courses => {:instructor =>
> {:office_building => [:address, :manager]}}}
>
> will find all students. For each student it will also fetch the 'courses'
> for that student. For each of those courses it will also fetch the
> instructor for that course. And while it's doing that it will grab the
> office_building for the instructor. Then it will grab the address of the
> office building and the manager of the office building.
>
> A simple array example:
>
> Student.find(:all, :include => [:courses, :addresses, :dorm_room, {:advisor
> => :office_building}]
>
> This will find each student, and for each student it will also fetch that
> student's course list, that student's address, that student's dorm room,
> that student's advisor, and the advisor's office building.
>
> So arrays are lists of associations on the model (or key model if it's a
> hash). Hashes are also lists of associations on the model, but only the keys
> are associated to the model. The values are associated to the key model.
>
> I'm not sure I said that very clearly, I guess I made up for it in quantity.
>
> -Eric
>