lib/sequel/plugins/many_through_many.rb in sequel-3.28.0 vs lib/sequel/plugins/many_through_many.rb in sequel-3.29.0
- old
+ new
@@ -61,15 +61,12 @@
# The hash key to use for the eager loading predicate (left side of IN (1, 2, 3))
def eager_loading_predicate_key
self[:eager_loading_predicate_key] ||= begin
calculate_edges
e = self[:edges].first
- if self[:uses_left_composite_keys]
- e[:right].map{|k| SQL::QualifiedIdentifier.new(e[:table], k)}
- else
- SQL::QualifiedIdentifier.new(e[:table], e[:right])
- end
+ f = self[:final_reverse_edge]
+ qualify(f[:alias], e[:right])
end
end
# The list of joins to use when eager graphing
def edges
@@ -198,13 +195,12 @@
rows = eo[:rows]
rows.each{|object| object.associations[name] = []}
ds = opts.associated_class
opts.reverse_edges.each{|t| ds = ds.join(t[:table], Array(t[:left]).zip(Array(t[:right])), :table_alias=>t[:alias])}
ft = opts[:final_reverse_edge]
- conds = uses_lcks ? [[left_keys.map{|k| SQL::QualifiedIdentifier.new(ft[:table], k)}, h.keys]] : [[left_key, h.keys]]
- ds = ds.join(ft[:table], Array(ft[:left]).zip(Array(ft[:right])) + conds, :table_alias=>ft[:alias])
- ds = model.eager_loading_dataset(opts, ds, Array(opts.select), eo[:associations], eo)
+ ds = ds.join(ft[:table], Array(ft[:left]).zip(Array(ft[:right])) + [[opts.eager_loading_predicate_key, h.keys]], :table_alias=>ft[:alias])
+ ds = model.eager_loading_dataset(opts, ds, nil, eo[:associations], eo)
case opts.eager_limit_strategy
when :window_function
delete_rn = true
rn = ds.row_number_column
ds = apply_window_function_eager_limit_strategy(ds, opts)
@@ -260,18 +256,18 @@
lpks = ref[:left_primary_keys]
lpks = lpks.first if lpks.length == 1
edges = ref.edges
first, rest = edges.first, edges[1..-1]
last = edges.last
- ds = model.db[first[:table]].select(*Array(first[:right]).map{|x| ::Sequel::SQL::QualifiedIdentifier.new(first[:table], x)})
+ ds = model.db[first[:table]].select(*Array(ref.qualify(first[:table], first[:right])))
rest.each{|e| ds = ds.join(e[:table], e.fetch(:only_conditions, (Array(e[:right]).zip(Array(e[:left])) + e[:conditions])), :table_alias=>ds.unused_table_alias(e[:table]), &e[:block])}
last_alias = if rest.empty?
first[:table]
else
last_join = ds.opts[:join].last
last_join.table_alias || last_join.table
end
- exp = association_filter_key_expression(Array(ref[:final_edge][:left]).map{|x| ::Sequel::SQL::QualifiedIdentifier.new(last_alias, x)}, ref.right_primary_keys, obj)
+ exp = association_filter_key_expression(ref.qualify(last_alias, Array(ref[:final_edge][:left])), ref.right_primary_keys, obj)
if exp == SQL::Constants::FALSE
association_filter_handle_inversion(op, exp, Array(lpks))
else
ds = ds.where(exp).exclude(SQL::BooleanExpression.from_value_pairs(ds.opts[:select].zip([]), :OR))
association_filter_handle_inversion(op, SQL::BooleanExpression.from_value_pairs(lpks=>ds), Array(lpks))