Class | Sequel::Model::Associations::ManyToManyAssociationReflection |
In: |
lib/sequel/model/associations.rb
|
Parent: | AssociationReflection |
The alias to use for the associated key when eagerly loading
# File lib/sequel/model/associations.rb, line 234 234: def associated_key_alias 235: self[:left_key_alias] 236: end
The column to use for the associated key when eagerly loading
# File lib/sequel/model/associations.rb, line 239 239: def associated_key_column 240: self[:left_key] 241: end
The table containing the column to use for the associated key when eagerly loading
# File lib/sequel/model/associations.rb, line 244 244: def associated_key_table 245: self[:join_table] 246: end
The default associated key alias
# File lib/sequel/model/associations.rb, line 249 249: def default_associated_key_alias 250: :x_foreign_key_x 251: end
Default name symbol for the join table.
# File lib/sequel/model/associations.rb, line 254 254: def default_join_table 255: [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym 256: end
Default foreign key name symbol for key in join table that points to current table‘s primary key (or :left_primary_key column).
# File lib/sequel/model/associations.rb, line 260 260: def default_left_key 261: 262: "#{underscore(demodulize(self[:model].name))}_id" 263: end
Default foreign key name symbol for foreign key in join table that points to the association‘s table‘s primary key (or :right_primary_key column).
# File lib/sequel/model/associations.rb, line 266 266: def default_right_key 267: 268: "#{singularize(self[:name])}_id" 269: end
The key to use for the key hash when eager loading
# File lib/sequel/model/associations.rb, line 271 271: def eager_loader_key 272: self[:left_primary_key] 273: end
Whether the associated object needs a primary key to be added/removed, true for many_to_many associations.
# File lib/sequel/model/associations.rb, line 282 282: def need_associated_primary_key? 283: true 284: end
Returns the reciprocal association symbol, if one exists.
# File lib/sequel/model/associations.rb, line 287 287: def reciprocal 288: return self[:reciprocal] if include?(:reciprocal) 289: left_key = self[:left_key] 290: right_key = self[:right_key] 291: join_table = self[:join_table] 292: associated_class.all_association_reflections.each do |assoc_reflect| 293: if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_key] == right_key && 294: assoc_reflect[:right_key] == left_key && assoc_reflect[:join_table] == join_table && 295: assoc_reflect.associated_class == self[:model] 296: return self[:reciprocal] = assoc_reflect[:name] 297: end 298: end 299: self[:reciprocal] = nil 300: end
The primary key column to use in the associated table.
# File lib/sequel/model/associations.rb, line 303 303: def right_primary_key 304: self[:right_primary_key] ||= associated_class.primary_key 305: end
The columns to select when loading the association, associated_class.table_name.* by default.
# File lib/sequel/model/associations.rb, line 308 308: def select 309: return self[:select] if include?(:select) 310: self[:select] ||= Sequel::SQL::ColumnAll.new(associated_class.table_name) 311: end