Thanks Jeremy, that's exactly what I was looking for!
On Tuesday, July 9, 2019 at 4:11:45 PM UTC-7, Jeremy Evans wrote:
>
> 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/1e8c55d3-1341-4db6-b5cf-8b5a8c95e77b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.