On Sunday, August 27, 2017 at 4:27:59 PM UTC-7, Carlos Azuaje wrote:
>
> Hello, I have a question:
>
> I have 3 tables snippet, comment_snippets, and users and i need a query to 
> bring the names of users who wrote a comment...
>
> *How can I add a column of a child table when making a query to its parent 
> table?*
>
> I am trying to change the option: dataset in my Model named Snippet so 
> that when doing something like this:
>
> id = 1
> comment_with_the_name_of_the_user = Snippet[id].comment_snippets
>
>
> The dataset comment_with_the_name_of_the_user contains the column  `name` 
>  of the `users` table associated with `comment_snippets` table.
>
> This is the  model snippet
>
> class Snippet < Sequel :: Model(:snippets)
>    many_to_one: :users
>    one_to_many: comment_snippets,
>                Dataset: proc {
>                  CommentSnippet.select_all (: comment_snippets) .join (
>                      :users
>                  )
>                }
> end
>
>
> Now, i try this: 
>
> class Snippet < Sequel :: Model(:snippets)
>    many_to_one: :users
>    one_to_many: comment_snippets,
>                Dataset: proc {
>                  CommentSnippet.select_all (: comment_snippets) .join (
>                      :users
>                  ).select(:name) # Name of the user that writed the 
> comment
>                }
> end
>
> But when i run the test it gives me this error:
>
> NoMethodError:
>        undefined method `name' for #<CommentSnippet 
> @values={:name=>"Audrey"}>
>
>
> The test:
>
> it 'should name equal to Audrey' do
>   expect(Snippet[@snippet.id].comment_snippets[0].values).to include(:name
> )
> end
>
>
>
>
> I think I'm coming to make it work but I do not know which is the right 
> way, any ideas?
>

I answered this in the issue you posted to GitHub: 
 https://github.com/jeremyevans/sequel/issues/1411

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