Oh, I wasn't fully aware that the association conditions are applied at the
"ON" level, and not on the joined dataset level (making it a subquery). I see
now how it really doesn't make sense for :order to do anything on joining.
Thank you for patiently explaining it to me.
> In your example, you are already changing the table being joined to use a
> subquery, so you should just add the order at that point.
>
> Artist.association_join(albums: -> (ds) {
> ds.distinct(:artist_id).order(:artist_id, :created_at) })
Yes, this is what I've done in the end.
Kind regards,
Janko
On 21 Jan 2019, 18:28 +0100, Jeremy Evans <[email protected]>, wrote:
> On Monday, January 21, 2019 at 5:27:06 AM UTC-8, Janko Marohnić wrote:
> > Hi Jeremy, thank you for the explanation, that makes sense.
> >
> > If the only thing that would happen is that the ORDER BY of the joined
> > dataset wouldn't be applied, then I might argue that Sequel could still add
> > it (like it does conditions) so that it works correctly if you use DISTINCT
> > ON. But if that ORDER BY could cause errors in some databases without any
> > limits, as you mentioned, then we certainly want to avoid it.
>
> The documentation is clear that association_join only adds joins and does not
> make other modifications to the query:
> http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/Associations/DatasetMethods.html#method-i-association_join
>
> Sequel never added the order to the table/subquery being joined, so it
> doesn't make sense for association_join to do so, especially considering in
> general it would be meaningless or break things. This is different than
> association conditions, which are used to modify the join itself (the ON
> condition).
>
> In your example, you are already changing the table being joined to use a
> subquery, so you should just add the order at that point.
>
> Artist.association_join(albums: -> (ds) {
> ds.distinct(:artist_id).order(:artist_id, :created_at) })
>
> 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/vJlG07_QKQM/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.