| Class | Sequel::Model::Associations::ManyToManyAssociationReflection |
| In: |
lib/sequel/model/associations.rb
|
| Parent: | AssociationReflection |
Default name symbol for the join table.
# File lib/sequel/model/associations.rb, line 227
227: def default_join_table
228: [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
229: 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 233
233: def default_left_key
234:
235: "#{underscore(demodulize(self[:model].name))}_id"
236: 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 239
239: def default_right_key
240:
241: "#{singularize(self[:name])}_id"
242: end
The key to use for the key hash when eager loading
# File lib/sequel/model/associations.rb, line 244
244: def eager_loader_key
245: self[:left_primary_key]
246: 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 250
250: def need_associated_primary_key?
251: true
252: end
Returns the reciprocal association symbol, if one exists.
# File lib/sequel/model/associations.rb, line 255
255: def reciprocal
256: return self[:reciprocal] if include?(:reciprocal)
257: left_key = self[:left_key]
258: right_key = self[:right_key]
259: join_table = self[:join_table]
260: associated_class.all_association_reflections.each do |assoc_reflect|
261: if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_key] == right_key \
262: && assoc_reflect[:right_key] == left_key && assoc_reflect[:join_table] == join_table
263: return self[:reciprocal] = assoc_reflect[:name]
264: end
265: end
266: self[:reciprocal] = nil
267: end
The primary key column to use in the associated table.
# File lib/sequel/model/associations.rb, line 270
270: def right_primary_key
271: self[:right_primary_key] ||= associated_class.primary_key
272: end
The columns to select when loading the association, associated_class.table_name.* by default.
# File lib/sequel/model/associations.rb, line 275
275: def select
276: return self[:select] if include?(:select)
277: self[:select] ||= Sequel::SQL::ColumnAll.new(associated_class.table_name)
278: end