Class Index [+]

Quicksearch

Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection

The AssociationReflection subclass for many_through_many associations.

Public Instance Methods

default_associated_key_alias() click to toggle source

The default associated key alias(es) to use when eager loading associations via eager.

    # File lib/sequel/plugins/many_through_many.rb, line 52
52:         def default_associated_key_alias
53:           self[:uses_left_composite_keys] ? (0...self[:through].first[:left].length).map{|i| :"x_foreign_key_#{i}_x"} : :x_foreign_key_x
54:         end
reciprocal() click to toggle source

Many through many associations don’t have a reciprocal

    # File lib/sequel/plugins/many_through_many.rb, line 65
65:         def reciprocal
66:           nil
67:         end

Private Instance Methods

calculate_edges() click to toggle source

Transform the :through option into a list of edges and reverse edges to use to join tables when loading the association.

     # File lib/sequel/plugins/many_through_many.rb, line 89
 89:         def calculate_edges
 90:           es = [{:left_table=>self[:model].table_name, :left_key=>self[:left_primary_key]}]
 91:           self[:through].each do |t|
 92:             es.last.merge!(:right_key=>t[:left], :right_table=>t[:table], :join_type=>t[:join_type]||self[:graph_join_type], :conditions=>(t[:conditions]||[]).to_a, :block=>t[:block])
 93:             es.last[:only_conditions] = t[:only_conditions] if t.include?(:only_conditions)
 94:             es << {:left_table=>t[:table], :left_key=>t[:right]}
 95:           end
 96:           es.last.merge!(:right_key=>right_primary_key, :right_table=>associated_class.table_name)
 97:           edges = es.map do |e| 
 98:             h = {:table=>e[:right_table], :left=>e[:left_key], :right=>e[:right_key], :conditions=>e[:conditions], :join_type=>e[:join_type], :block=>e[:block]}
 99:             h[:only_conditions] = e[:only_conditions] if e.include?(:only_conditions)
100:             h
101:           end
102:           reverse_edges = es.reverse.map{|e| {:table=>e[:left_table], :left=>e[:left_key], :right=>e[:right_key]}}
103:           reverse_edges.pop
104:           calculate_reverse_edge_aliases(reverse_edges)
105:           final_reverse_edge = reverse_edges.pop
106:           final_reverse_alias = final_reverse_edge[:alias]
107: 
108:           h = {:final_edge=>edges.pop,
109:                :final_reverse_edge=>final_reverse_edge,
110:                :edges=>edges,
111:                :reverse_edges=>reverse_edges,
112:                :eager_loading_predicate_key=>qualify(final_reverse_alias, edges.first[:right]),
113:                :associated_key_table=>final_reverse_edge[:alias],
114:           }
115:           h.each{|k, v| cached_set(k, v)}
116:           h
117:         end
calculate_reverse_edge_aliases(reverse_edges) click to toggle source

Make sure to use unique table aliases when lazy loading or eager loading

    # File lib/sequel/plugins/many_through_many.rb, line 72
72:         def calculate_reverse_edge_aliases(reverse_edges)
73:           aliases = [associated_class.table_name]
74:           reverse_edges.each do |e|
75:             table_alias = e[:table]
76:             if aliases.include?(table_alias)
77:               i = 0
78:               table_alias = loop do
79:                 ta = :"#{table_alias}_#{i}"
80:                 break ta unless aliases.include?(ta)
81:                 i += 1
82:               end
83:             end
84:             aliases.push(e[:alias] = table_alias)
85:           end
86:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.