| 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 273
273: def associated_key_alias
274: self[:left_key_alias]
275: end
The column to use for the associated key when eagerly loading
# File lib/sequel/model/associations.rb, line 278
278: def associated_key_column
279: self[:left_key]
280: end
The table containing the column to use for the associated key when eagerly loading
# File lib/sequel/model/associations.rb, line 283
283: def associated_key_table
284: self[:join_table]
285: end
many_to_many associations can only have associated objects if none of the :left_primary_keys options have a nil value.
# File lib/sequel/model/associations.rb, line 289
289: def can_have_associated_objects?(obj)
290: !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
291: end
The default associated key alias(es) to use when eager loading associations via eager.
# File lib/sequel/model/associations.rb, line 295
295: def default_associated_key_alias
296: self[:uses_left_composite_keys] ? (0...self[:left_keys].length).map{|i| "x_foreign_key_#{i}_x""x_foreign_key_#{i}_x"} : :x_foreign_key_x
297: end
Default name symbol for the join table.
# File lib/sequel/model/associations.rb, line 300
300: def default_join_table
301: [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
302: 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 306
306: def default_left_key
307:
308: "#{underscore(demodulize(self[:model].name))}_id"
309: 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 312
312: def default_right_key
313:
314: "#{singularize(self[:name])}_id"
315: end
The key to use for the key hash when eager loading
# File lib/sequel/model/associations.rb, line 317
317: def eager_loader_key
318: self[:left_primary_key]
319: 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 328
328: def need_associated_primary_key?
329: true
330: end
Returns the reciprocal association symbol, if one exists.
# File lib/sequel/model/associations.rb, line 333
333: def reciprocal
334: return self[:reciprocal] if include?(:reciprocal)
335: left_keys = self[:left_keys]
336: right_keys = self[:right_keys]
337: join_table = self[:join_table]
338: associated_class.all_association_reflections.each do |assoc_reflect|
339: if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
340: assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
341: assoc_reflect.associated_class == self[:model]
342: return self[:reciprocal] = assoc_reflect[:name]
343: end
344: end
345: self[:reciprocal] = nil
346: end
The primary key column(s) to use in the associated table (can be symbol or array).
# File lib/sequel/model/associations.rb, line 349
349: def right_primary_key
350: self[:right_primary_key] ||= associated_class.primary_key
351: end
The primary key columns to use in the associated table (always array).
# File lib/sequel/model/associations.rb, line 354
354: def right_primary_keys
355: self[:right_primary_keys] ||= Array(right_primary_key)
356: end
The columns to select when loading the association, associated_class.table_name.* by default.
# File lib/sequel/model/associations.rb, line 360
360: def select
361: return self[:select] if include?(:select)
362: self[:select] ||= Sequel::SQL::ColumnAll.new(associated_class.table_name)
363: end