On Sunday, October 30, 2016 at 10:42:36 PM UTC+1, Andrew Burleson wrote:
>
> I have two tables like this:
>
> Conversation
> :id
> :user_id # the user who started the conversation
>
>
> Message
> :id
> :conversation_id # the conversation this message is part of
> :user_id # the user who posted this particular message
> :text
>
>
> These are Sequel::Model classes, set up as you might expect
>
> Conversation.one_to_many :messages
> Message.many_to_one :conversation
>
>
> Now, I'd like to do a query where I filter messages still grouped by 
> conversation. For example, let's say we have the following conversations:
>
> Conversation 1:
> - Message 1, User 1, text = "Hello world!"
> - Message 2, User 2, text = "Goodbye."
>
>
> Conversation 2:
> - Message 3, User 3, text = "ET?"
> - Message 4, User 1, text = "phone home"
>
>
> So, it's pretty easy to get all the conversations with their messages 
> loaded:
>
> Conversation.eager(:messages).all
>
> But when it comes to actually searching I need to join and filter on 
> message columns. Going through something like:
>
> Conversation.join(:messages, :conversation_id => 
> :id).where(:conversations__user_id 
> => 1)
>

Can't you do what you want using eager_graph instead of eager?

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