Awesome, that worked :)

I will then probably send a PR to the #association_join RDocs to make this
more clear, as I didn't encounter any examples of this.

Thanks!

Kind regards,
Janko

On Wed, Sep 12, 2018 at 3:42 PM Jeremy Evans <[email protected]> wrote:

> 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 a topic in the
> Google Groups "sequel-talk" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sequel-talk/qi-AEIrvHgE/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>

-- 
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