On Sunday, October 6, 2013 12:16:43 AM UTC-7, Robert Payne wrote:

> I have some eager loading that I need to make happen sometimes on single 
> rows and other times for lists. See the code sample below with some 
> comments but I was curious if there is any (technical) reason why .first 
> and .first! should not perform eager loading or if there is a better work 
> around than using .all.first and then raising the errors myself?
>
> class User < Sequel::Model(:users)
>
>   dataset_module do
>
>     def eager_relationships
>       # setup some eager loads here 
>     end    
>
>   end
>
> end
>
> User.where(id: [1,2,3]).eager_relationships.all # eager loads
> User.where(id: 1).eager_relationships.first! # does not eager load
>
> User.dataset = User.dataset.clone.eager_relationships # will make first, 
> all, each eager load
>

You cannot do eager loading without having all rows up front.  If you 
really want first/first! to work, you can use the eager_each plugin on the 
model (which forces the use of #all on eager datasets).

Note that there is generally no reason to do eager loading if you are only 
returning a single object.

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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to