On Tuesday, July 9, 2019 at 1:14:52 PM UTC-7, marc halperin wrote:
>
> I need to be able to take a Dataset object and for any join's where both 
> tables contain a particular column 'x' I want to add to the on condition 
> '... AND A.x=B.x' (where A and B are the tables already set to be join in 
> the Dataset object).  It looks like I may be able to manipulate the 
> JoinOnClause objects associated with the Dataset object by getting 
> opts[:join] but I wasn't sure if there were any specialized functions for 
> doing this like select_append is for selects. 
>

 Unfortunately, there can be more than two tables in a dataset.  For only 
two tables, you could do something like:

DB.extend_datasets do
  def join_table(_, table, *)
    return super if opts[:join]

    ds = super
    join = ds.opts[:join][0]
    if join.is_a?(Sequel::SQL::JoinOnClause)
      if db.from(join.table_expr).columns.include?(:x) && 
columns.include?(:x) && join.on.is_a?(Sequel::SQL::BooleanExpression)
        ds = ds.clone(:join=>[Sequel::SQL::JoinOnClause.new(join.on & 
{Sequel.qualify(join.table, :x) => Sequel.qualify(first_source, :x)}, 
join.join_type, join.table_expr)])
      end
    end

    ds
  end
end

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/caa2940e-49a9-4ba6-9458-0fb6333785d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to