Here's something I'd love to do.  I would like to traverse several
associations and select all the matching model objects from the last
model in the chain, without getting the results for the other tables.
No combined results, no graphs, just model objects from the last table
in the join.  And I'd like this to happen in just one SQL query.

modelA_object.assocB_dataset.assocC_dataset.assocD_dataset.all

#=>
SELECT tableD.*
  FROM tableB
  JOIN tableC ON (...)
  JOIN tableD ON (...)
 WHERE tableB.tableA = #{modelA_object.id}

(modified by any conditions, orders, or other options of the
associations involved)

This may require making datasets "model-aware," meaning aware of the
model from which they originated, so they can access the model's
associations and other methods.  This might be useful in other cases
too; I've found myself wishing that datasets had model-awareness on
more than one occasion.

Shawn

On Apr 15, 8:30 am, Jeremy Evans <[email protected]> wrote:
> On Apr 14, 3:02 pm, John Firebaugh <[email protected]> wrote:
>
> > I remember having a hard time finding basic documentation for models,
> > particularly model associations. There's some documentation in the
> > README, but I was looking for a guide linked to 
> > fromhttp://sequel.rubyforge.org/documentation.htmlthatspecifically
> > covered those areas in a bit more depth. I felt like there was a gap
> > there between what's in the README and what's in the rdocs,
> > particularly since the relevant rdocs are partitioned between class,
> > instance, and association class methods in a way that makes it
> > difficult for a newcomer to get an overall grasp on models.
>
> True.  I should probably add a basic associations RDoc page in
> addition to the current advanced associations RDoc page.  Added to the
> todo list.
>
> Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to