Hello again,
just a quick info. I'm using latest Sequel 5.49

Best regards
--Armin


armin schrieb am Mittwoch, 6. Oktober 2021 um 15:57:30 UTC+2:

> Hello Mr. Evans,
>
> I want to create 2 model-classes. A booking model which has a 
> one_to_many-connection to a service model. I want to load some bookings and 
> eager load the services.
>
> The difficulty is that the source of the two models relates to complex 
> sqls, which I cannot change or put it into sequel-dsl. I tried following:
>
> class Booking < Sequel::Model(DB["select complex.id id, ...."])
>    one_to_many :services, key: :booking_id
> end
>
> class Service < Sequel::Model(DB["select complex.id id, 
> complex.booking_id...."])
>    one_to_many :services, key: :booking_id
> end
>
> Now I want to eager load the bookings:
> Booking.eager(:services).limit(5).to_a, but get a 
> Sequel::Error:
>        No source specified for query
> if I try to access booking.services
>
> Basic filtering is also ignored. Following returns bookings, but 
> unfiltered.
>
> Booking.where(id: 1).to_a
>
> and following returns just the booking with the given id.
>
> Booking.limit(10000).where(id: 1).to_a
>
> The limit-method-call makes it work. I do not know why.
>
> How I can achieve my goal? I'm just using models, because I want to eager 
> load the services. The result should be bookings holding their services. 
> Whether 
> it is a hash or a model object is not so important. 
> Or do I have to do the association-loading manually in this case:
> 1. Load a punch of services
> 2. Load the services of 1 and distribute the services to the 
> corresponding bookings
>
> It would be nice, if you could help me.
>
> Thank you very much
> Best regards
> --Armin
>

-- 
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/fd7273b0-cc9d-4f9f-bdf2-8f4ab4d53778n%40googlegroups.com.

Reply via email to