On Wednesday, September 12, 2018 at 4:04:26 AM UTC-7, Janko Marohnić wrote:
>
> Hello Jeremy,
>
> I'm trying to figure out how can I do a cascading association join, so 
> that for
>
>   class Artist < Sequel::Model
>   end
>
>   class Album < Sequel::Model
>     many_to_one :artist
>   end
>
>   class Song < Sequel::Model
>     many_to_one :album
>   end
>
> I generate the equivalent query to:
>
>   Song
>     .join(:albums, Sequel[:albums][:id] => Sequel[:songs][:album_id])
>     .join(:artists, Sequel[:artists][:id] => Sequel[:albums][:artist_id])
>
> But using #association_join instead of #join to avoid having to repeat 
> JOIN arguments that are already defined by the associations.
>

association_join takes the same arguments as eager_graph, so you should be 
able to do:

 Song.association_join(:album=>:artist)

This will alias the joined tables to match the association names (just as 
eager_graph does).

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to