| Class | Sequel::Model::Associations::ManyToManyAssociationReflection |
| In: |
lib/sequel_model/association_reflection.rb
|
| Parent: | AssociationReflection |
Default name symbol for the join table.
# File lib/sequel_model/association_reflection.rb, line 213
213: def default_join_table
214: ([self[:class_name].demodulize, self[:model].name.to_s.demodulize]. \
215: map{|i| i.pluralize.underscore}.sort.join('_')).to_sym
216: 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/association_reflection.rb, line 220
220: def default_left_key
221:
222: "#{self[:model].name.to_s.demodulize.underscore}_id"
223: 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/association_reflection.rb, line 226
226: def default_right_key
227:
228: "#{self[:name].to_s.singularize}_id"
229: end
The key to use for the key hash when eager loading
# File lib/sequel_model/association_reflection.rb, line 231
231: def eager_loader_key
232: self[:left_primary_key]
233: end
Whether the associated object needs a primary key to be added/removed, true for many_to_many associations.
# File lib/sequel_model/association_reflection.rb, line 237
237: def need_associated_primary_key?
238: true
239: end
Returns/sets the reciprocal association variable, if one exists
# File lib/sequel_model/association_reflection.rb, line 242
242: def reciprocal
243: return self[:reciprocal] if include?(:reciprocal)
244: left_key = self[:left_key]
245: right_key = self[:right_key]
246: join_table = self[:join_table]
247: associated_class.all_association_reflections.each do |assoc_reflect|
248: if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_key] == right_key \
249: && assoc_reflect[:right_key] == left_key && assoc_reflect[:join_table] == join_table
250: return self[:reciprocal] = assoc_reflect[:name]
251: end
252: end
253: self[:reciprocal] = nil
254: end