lib/sequel/plugins/many_through_many.rb in sequel-4.13.0 vs lib/sequel/plugins/many_through_many.rb in sequel-4.14.0
- old
+ new
@@ -18,13 +18,13 @@
# [[:albums_artists, :artist_id, :album_id],
# [:albums_tags, :album_id, :tag_id]]
#
# This argument is an array of arrays with three elements. Each entry in the main array represents a JOIN in SQL:
#
- # * The first element in each array represents the name of the table to join.
- # * The second element in each array represents the column used to join to the previous table.
- # * The third element in each array represents the column used to join to the next table.
+ # first element :: represents the name of the table to join.
+ # second element :: represents the column used to join to the previous table.
+ # third element :: represents the column used to join to the next table.
#
# So the "Artist.many_through_many :tags" is translated into something similar to:
#
# FROM artists
# JOIN albums_artists ON (artists.id = albums_artists.artist_id)
@@ -178,25 +178,25 @@
include Sequel::Model::Associations::SingularAssociationReflection
end
module ClassMethods
# Create a many_through_many association. Arguments:
- # * name - Same as associate, the name of the association.
- # * through - The tables and keys to join between the current table and the associated table.
- # Must be an array, with elements that are either 3 element arrays, or hashes with keys :table, :left, and :right.
- # The required entries in the array/hash are:
- # :table (first array element) :: The name of the table to join.
- # :left (middle array element) :: The key joining the table to the previous table. Can use an
- # array of symbols for a composite key association.
- # :right (last array element) :: The key joining the table to the next table. Can use an
- # array of symbols for a composite key association.
- # If a hash is provided, the following keys are respected when using eager_graph:
- # :block :: A proc to use as the block argument to join.
- # :conditions :: Extra conditions to add to the JOIN ON clause. Must be a hash or array of two pairs.
- # :join_type :: The join type to use for the join, defaults to :left_outer.
- # :only_conditions :: Conditions to use for the join instead of the ones specified by the keys.
- # * opts - The options for the associaion. Takes the same options as many_to_many.
+ # name :: Same as associate, the name of the association.
+ # through :: The tables and keys to join between the current table and the associated table.
+ # Must be an array, with elements that are either 3 element arrays, or hashes with keys :table, :left, and :right.
+ # The required entries in the array/hash are:
+ # :table (first array element) :: The name of the table to join.
+ # :left (middle array element) :: The key joining the table to the previous table. Can use an
+ # array of symbols for a composite key association.
+ # :right (last array element) :: The key joining the table to the next table. Can use an
+ # array of symbols for a composite key association.
+ # If a hash is provided, the following keys are respected when using eager_graph:
+ # :block :: A proc to use as the block argument to join.
+ # :conditions :: Extra conditions to add to the JOIN ON clause. Must be a hash or array of two pairs.
+ # :join_type :: The join type to use for the join, defaults to :left_outer.
+ # :only_conditions :: Conditions to use for the join instead of the ones specified by the keys.
+ # opts :: The options for the associaion. Takes the same options as many_to_many.
def many_through_many(name, through, opts=OPTS, &block)
associate(:many_through_many, name, opts.merge(through.is_a?(Hash) ? through : {:through=>through}), &block)
end
# Creates a one_through_many association. See many_through_many for arguments.
@@ -255,17 +255,17 @@
ft = opts.final_reverse_edge
egds = egds.join(ft[:table], Array(ft[:left]).zip(Array(ft[:right])), :table_alias=>ft[:alias], :qualify=>:deep).
select_all(egds.first_source).
select_append(*associated_key_array)
egds = opts.apply_eager_graph_limit_strategy(egls, egds)
- ds.graph(egds, associated_key_array.map{|v| v.alias}.zip(Array(lpkcs)) + conditions, :qualify=>:deep, :table_alias=>eo[:table_alias], :implicit_qualifier=>iq, :join_type=>eo[:join_type]||join_type, :from_self_alias=>eo[:from_self_alias], :select=>select||orig_egds.columns, &graph_block)
+ ds.graph(egds, associated_key_array.map{|v| v.alias}.zip(Array(lpkcs)) + conditions, :qualify=>:deep, :table_alias=>eo[:table_alias], :implicit_qualifier=>iq, :join_type=>eo[:join_type]||join_type, :join_only=>eo[:join_only], :from_self_alias=>eo[:from_self_alias], :select=>select||orig_egds.columns, &graph_block)
else
opts.edges.each do |t|
- ds = ds.graph(t[:table], t.fetch(:only_conditions, (Array(t[:right]).zip(Array(t[:left])) + t[:conditions])), :select=>false, :table_alias=>ds.unused_table_alias(t[:table]), :join_type=>eo[:join_type]||t[:join_type], :qualify=>:deep, :implicit_qualifier=>iq, :from_self_alias=>eo[:from_self_alias], &t[:block])
+ ds = ds.graph(t[:table], t.fetch(:only_conditions, (Array(t[:right]).zip(Array(t[:left])) + t[:conditions])), :select=>false, :table_alias=>ds.unused_table_alias(t[:table]), :join_type=>eo[:join_type]||t[:join_type], :join_only=>eo[:join_only], :qualify=>:deep, :implicit_qualifier=>iq, :from_self_alias=>eo[:from_self_alias], &t[:block])
iq = nil
end
fe = opts.final_edge
- ds.graph(opts.associated_class, use_only_conditions ? only_conditions : (Array(opts.right_primary_key).zip(Array(fe[:left])) + conditions), :select=>select, :table_alias=>eo[:table_alias], :qualify=>:deep, :join_type=>eo[:join_type]||join_type, &graph_block)
+ ds.graph(opts.associated_class, use_only_conditions ? only_conditions : (Array(opts.right_primary_key).zip(Array(fe[:left])) + conditions), :select=>select, :table_alias=>eo[:table_alias], :qualify=>:deep, :join_type=>eo[:join_type]||join_type, :join_only=>eo[:join_only], &graph_block)
end
end
end
# Use def_many_through_many, since they share pretty much the same code.