On Saturday, January 10, 2015 at 11:16:14 PM UTC-8, Horacio Peña wrote:
>
> Thanks! I missed that.
>
> I am using eager_graph because i need to filter by fields on the 
> associated objects. Is there a cleaner way? (i want something like select 
> T.* from T join T2 using (...) where T2.x=y limit 1;) And, if I need to 
> make the join, why would I want to avoid the eager loading of the 
> associated object?
>

If you are just doing it to filter and not because you need to access the 
associated objects, use association_join (and maybe select_all).  Eager 
loading when you aren't accessing the associated objects is wasteful.

If you are going to be accessing the associated objects and you need to 
filter, then eager graphing is fine if you are only returning a single 
record, but you need to be careful if you are eager graphing plural 
associations (e.g. one_to_many, many_to_many).  In your example, you 
aren't, so .limit(1).all[0] is fine.
 

> BTW, why does .first uses each? I would assumed .first was equivalent to 
> .limit(1).all[0]
>

The each approach is simpler and faster.  At the dataset level, almost all 
actions call each and not all.  The only action that currently calls all is 
first when provided with an integer argument (e.g. first(10)).

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/d/optout.

Reply via email to