On Tuesday, August 18, 2020 at 2:10:44 AM UTC-7, David Espada wrote:
>
> Hi everybody.
>
> If I have this simple model:
> ----------------------
> class Operator < Sequel::Model
>   one_to_many :directions
> end
>
> class Direction < Sequel::Model
>   many_to_one :operator
> end
> ----------------------
>
> I'd like to load an operator with all their directions in one quey. How 
> can I do it with :eager options. :eager option is not usable in this case 
> and I don't know it there is any other possibility.
>

In general it doesn't make much sense to load a single operator and all 
directions in one query.  You would generally want to use two queries, one 
for the single operator, and another for the operator's directions.  
However, if you do want to use a single query:

  operator = 
Operator.where(Sequel[:operators][:id]=>operator_id).eager_graph(:directions).all.first

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/deb76d30-6051-4a6a-8b41-e7c2983e7c75o%40googlegroups.com.

Reply via email to