On Thursday, November 10, 2016 at 1:40:06 PM UTC-8, Andrew Burleson wrote:
>
> Hey Jeremy, thanks so much for this answer. After some fiddling around I 
> got it to do what I wanted, but now I ran into another interesting side 
> effect.
>
> When it comes to limiting the results, I'd ideally like to limit by a 
> total number of conversations and load however many messages that happened 
> to include. IE: load three conversations, and if each conversation has 5 
> messages or 50 messages, I don't really care.
>
> When I use .limit on the end of that eager graph, it's limiting the total 
> number of messages coming through, which I think I understand from a 
> dataset point of view.
>
> However, since that's not really the behavior I want, is there any way to 
> limit on the number of conversations returned instead of the number of 
> messages?
>

It would be better to describe the SQL you want to execute.  Since you 
didn't do that, my guess is you want something like:

  ds = Conversation.eager_graph(:messages=>:user).where{{users[:id]=>1}}
  
ds.where{{conversations[:id]=>ds.select(conversations[:id]).from_self.distinct.order(:id).limit(3)}}.all

That makes the limit pick the first three matching conversations by id. If 
you want to limit based on an existing order on the dataset, that's going 
to be more involved.  In that case, you really need to describe what SQL 
you want to execute.

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.

Reply via email to