On Friday, January 4, 2019 at 8:57:19 AM UTC-8, Janko Marohnić wrote:
>
> The following example:
>
> require "sequel"
>
> DB = Sequel.mock
>
> class Artist < Sequel::Model
>   one_to_many :albums, order: :created_at
> end
>
> class Album < Sequel::Model
> end
>
> puts Artist.association_join(:albums).sql
>
> prints out the following SQL:
>
> SELECT * FROM artists INNER JOIN albums ON (albums.artist_id = artists.id)
>
> and I was hoping it would be
>
> SELECT * FROM artists INNER JOIN (SELECT * FROM albums ORDER BY created_at
> ) AS albums ON (albums.artist_id = artists.id)
>
> The scenario where I wanted this ORDER BY to be added was when adding a 
> `DISTINCT ON`, e.g. to JOIN only on the earliest albums for each artist:
>
> Artist.association_join(albums: -> (ds) { ds.distinct(:artist_id) })
>
> Is the order left out intentionally? If not, I could send a pull request 
> for #association_join to pick up the default :order.
>

Yes, this is intentional.  association_join only adds the join, not any 
other changes made by the eager_graph code.  association_join is basically 
a shortcut for manual calls to join.

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