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.