On Fri, Oct 15, 2021 at 2:30 PM aryk....@gmail.com <aryk.gr...@gmail.com> wrote:
> I'm trying to do the example in the docs: > > > https://sequel.jeremyevans.net/rdoc/files/doc/advanced_associations_rdoc.html > > > Artist.one_to_one :first_album, class: :Album, order: :release_date, > eager_limit_strategy: :distinct_on Artist.where(id: > [1,2]).eager(:first_album).all > > # SELECT DISTINCT ON (albums.artist_id) * # FROM albums # WHERE > (albums.artist_id IN (1, 2)) # ORDER BY albums.artist_id, release_date > > When I try to run this exact same instance with: > > one_to_one :last_edit, class: "PostEdit", order: :created_at, > eager_limit_strategy: :distinct_on > > I get: > > Post.where(:id=>[1,2]).eager(:last_edit) > > => #<Sequel::Postgres::Dataset: "SELECT \"posts\".* FROM \"posts\" WHERE > (\"id\" IN (1, 2))"> > > So it's leaving off the entire extra amount. > You aren't running the eager load, you are just seeing the results of Dataset#inspect. Add a Database logger and call #all on the dataset to see all queries it executes for the eager load. > Also, when I do Post.dataset.association_join(:last_edit), how do I have > it use a window function with a limit 1 and sort it by created_at? > association_join doesn't support passing a :limit_strategy, you have to use eager_graph_with_options for that. There's not a simple way to add support for options to association_join, since it takes a splat and any entry in the splat can be a hash. > I'm on Sequel 5.34.0 if that's helpful. > Upgrade, that's more than a year old. The current Sequel version it 5.49.0. :) 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 sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSd6ntphHj6vWRkaLbfn7k6_2tw2poGh_-%3DctELUA2r_3g%40mail.gmail.com.