Class: Sequel::Model::Associations::ManyToManyAssociationReflection

Class | Sequel::Model::Associations::ManyToManyAssociationReflection
In: | lib/sequel_model/association_reflection.rb
Parent: | AssociationReflection

### Methods

default_join_table default_left_key default_right_key eager_loader_key need_associated_primary_key? reciprocal right_primary_key select

### Public Instance methods

default_join_table()

Default name symbol for the join table.

[Source]

         # 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_left_key()

Default foreign key name symbol for key in join table that points to current table‘s primary key (or :left_primary_key column).

[Source]

         # 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_right_key()

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).

[Source]

         # File lib/sequel_model/association_reflection.rb, line 226
    226:     def default_right_key
    227:
    228:       "#{self[:name].to_s.singularize}_id"
    229:     end

eager_loader_key()

The key to use for the key hash when eager loading

[Source]

         # File lib/sequel_model/association_reflection.rb, line 231
    231:     def eager_loader_key
    232:       self[:left_primary_key]
    233:     end

need_associated_primary_key?()

Whether the associated object needs a primary key to be added/removed, true for many_to_many associations.

[Source]

         # File lib/sequel_model/association_reflection.rb, line 237
    237:     def need_associated_primary_key?
    238:       true
    239:     end

reciprocal()

Returns/sets the reciprocal association variable, if one exists

[Source]

         # 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

right_primary_key()

The primary key column to use in the associated table.

[Source]

         # File lib/sequel_model/association_reflection.rb, line 257
    257:     def right_primary_key
    258:       self[:right_primary_key] ||= associated_class.primary_key
    259:     end

select()

The columns to select when loading the association, associated_class.table_name.* by default.

[Source]

         # File lib/sequel_model/association_reflection.rb, line 262
    262:     def select
    263:      return self[:select] if include?(:select)
    264:      self[:select] ||= associated_class.table_name.*
    265:     end

[Validate]