On Wednesday, November 1, 2017 at 7:32:43 AM UTC+1, Milod wrote:
>
> Say I have some three tables in the database:
>
> DB.create_table :people do
>   primary_key :id
>   String :name
>   Integer :age
> end
>
> DB.create_table :employees do
>   primary_key :id
>   String :employee
>   Integer :salary
> end
>
> DB.create_table :customers do
>   primary_key :id
>   String :costomer
> end
>
> p = DB[:people]
> e = DB[:employees]
> c = DB[:customers]
>
>
> And I want to perform two joins across the three tables
>
> j1 = p.join(:employees, employee: :name)
> j2 = j1.join(:customers, customer: :name)
>
> j2 will generate a faulty SQL query (calling j2.all, e.g., will show 
> this). This is because it looks for the name column of the employees table 
> rather than the people table. 
>
> Is there any way to perform a join on costumers' costumer column and 
> people's name column, given the query j1 as a starting point? What exactly 
> are the semantics here? Is the default table who's column will be joined on 
> taken from prior given arguments to join, e.g. from :employees being the 
> first argument in the first call to join?
>

You just need to qualify the hash value of the second query (there are 
other ways, but that is the easiest):

  j2 = j1.join(:customers, customer: Sequel[:people][:name])

The semantics should be adequately explained by the documentation 
(http://sequel.jeremyevans.net/rdoc/files/doc/querying_rdoc.html#label-Implicit+Qualification),
 
but if you have specific questions that aren't covered there, please ask.

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