Hey,

I put together a proof of concept using Docker: 
https://github.com/greggilbert/sequel-association-test

If you look at doit.rb, you'll see two queries. The first one doesn't work 
(i.e. returns nil) but the second one does. I guess there's something about 
the eager_limit that's not right? And if you leave out the .eager line 
altogether, you get the first VendorRevision for each, not the last.

Let me know if there's anything else I can clarify.

- greg

On Wednesday, December 28, 2016 at 11:23:57 AM UTC-5, Jeremy Evans wrote:
>
> On Tuesday, December 27, 2016 at 4:32:16 PM UTC-8, Greg Gilbert wrote:
>>
>> Hey. So I have a one-to-many relationship from Vendor to VendorRevision. 
>> I want to grab all of the user's Vendors and the latest VendorRevision for 
>> each without doing an N+1 sort of thing. Here's what I've been trying, but 
>> nothing is working so far.
>>
>> class Vendor < Sequel::Model
>>   one_to_many :vendor_revisions, class: VendorRevision
>>   many_to_one :user
>> end
>> Vendor.one_to_one :last_edit, :class => :VendorRevision
>>
>> class VendorRevision < Sequel::Model
>>   many_to_one :vendor
>> end
>>
>> Then, when I try to do the query:
>>
>> vendors = Vendor
>>             .where(:user_id => 1)
>>             .eager(:last_edit => proc {|ds| 
>> ds.reverse_order(:created_at).clone(:eager_limit => 1) })
>>             .all
>>            
>> vendors.each do |v|
>>   p v.last_edit
>>   p '-'*50
>> end
>>
>> That just prints *nil* twice. I've tried it without the eager load, with 
>> doing it as a one_to_many, but nothing's working. Any ideas?
>>
>
> From what you've described, it appears you have two vendors and no edits. 
>  If you are getting the same behavior both with and without the eager load, 
> I can't think of anything else that would explain the behavior you've 
> described.
>
> If you still think something is wrong, please post a self contained 
> example showing the problem, including table creation and data loading.
>
> 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