On Wednesday, November 11, 2015 at 2:46:21 PM UTC-8, Jeremy Swartwood wrote:
>
> Is there a method on a dataset, to return the list of tables that are 
> currently part of the dataset's joins?
>
> *What I'm doing:*
> I've got code that builds up joins and adds in where conditions depending 
> on different situations.  However, if one of the joins already exists, the 
> join fails with the following error:
>
> *ERROR:  *Sequel::DatabaseError - Mysql::Error: Not unique table/alias: 
> 'account'
>
> A simple solution for me, would be if I could only do the join, unless the 
> dataset already contained the table in the join.  Is there a method that 
> provides the list of tables already joined?
>
>
> *Example issue with all hard coded joins to show point:*
>
> enrollees = Models::Enrollees.where(some conditions).qualify(enrollees)
>
> # Join to restrict enrollees based on the account_type
> enrollees = enrolees.join(:account, :enrollee_id, :enrollee_id)
> enrollees = enrolees.join(:account_type, :account_type_id, 
> :account_type_id)
> enrollees = enrollees.where(conditions)
>
> # Join to restrtict enrollees based on the account number
> enrollees = enrollees.join(:account, :enrollee_id, :enrollee_id)   # <--- 
> Error happens here, as the account table is already joined.  I wanted to do 
> something likethe model's associations method and check to see if the 
> tablename was in it, but dataset doesn't appear to have any sort of "joined 
> table list" method?
> enrollees = enrolees.where(conditions)
>

You can inspect the dataset :from and :join options to determine that 
information:

ds = DB[:t].join(:j, :id=>:t_id)
ds.opts[:from]
# => [:t]
ds.opts[:join].map(&:table_expr)
# => [:j]

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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to