On Monday, October 31, 2016 at 3:49:22 PM UTC+1, Andrew Burleson wrote:
>
> I guess I don't really understand how `eager_graph` works. Looking through
> all the examples it seems you need to set up a relation and all eager_graph
> to load it, but in this case what I'm specifically interested in is
> generating a query that I can pass variables into, not hardcoded
> constraints.
>
eager_graph just returns a dataset where the tables have been joined, and
you can filter/order that dataset just as you would any other dataset.
> The behavior I want to write would be something like this pseudo code:
>
>
> Conversation.with_messages_from_user_and_load_only_the_messages_from_this_user(user).all
>
> Where the output from the previous example would be:
>
> conversations #=> [Conversation[1], Conversation[2]]
>
> and if you looped like this:
>
> puts "Search results:"
> conversations.each do |conv|
> puts "Conversation #{conv.id}"
> conv.messages.each{|m| puts "#{m.user.name}:\n#{m.text}" }
> puts "----"
> end
>
> You'd get the following
>
> Search Result:
> Conversation 1
> User 1
> Hello, World!
> ----
> Conversation 2
> User 1
> phone home
> ----
>
> How would you do that with eager_graph?
>
conversations =
Conversation.eager_graph(:messages=>:user).where{{users[:id]=>1}}.all
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.