Class Sequel::Model::Associations::ManyToManyAssociationReflection
In: lib/sequel/model/associations.rb
Parent: AssociationReflection

Methods

Public Instance methods

The alias to use for the associated key when eagerly loading

[Source]

     # File lib/sequel/model/associations.rb, line 299
299:         def associated_key_alias
300:           self[:left_key_alias]
301:         end

The column to use for the associated key when eagerly loading

[Source]

     # File lib/sequel/model/associations.rb, line 304
304:         def associated_key_column
305:           self[:left_key]
306:         end

The table containing the column to use for the associated key when eagerly loading

[Source]

     # File lib/sequel/model/associations.rb, line 309
309:         def associated_key_table
310:           self[:join_table]
311:         end

Alias of right_primary_keys

[Source]

     # File lib/sequel/model/associations.rb, line 314
314:         def associated_object_keys
315:           right_primary_keys
316:         end

many_to_many associations can only have associated objects if none of the :left_primary_keys options have a nil value.

[Source]

     # File lib/sequel/model/associations.rb, line 320
320:         def can_have_associated_objects?(obj)
321:           !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
322:         end

The default associated key alias(es) to use when eager loading associations via eager.

[Source]

     # File lib/sequel/model/associations.rb, line 326
326:         def default_associated_key_alias
327:           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
328:         end

Default name symbol for the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 331
331:         def default_join_table
332:           [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
333:         end

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/associations.rb, line 337
337:         def default_left_key
338: 
339:           "#{underscore(demodulize(self[:model].name))}_id"
340:         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).

[Source]

     # File lib/sequel/model/associations.rb, line 343
343:         def default_right_key
344: 
345:           "#{singularize(self[:name])}_id"
346:         end

The key to use for the key hash when eager loading

[Source]

     # File lib/sequel/model/associations.rb, line 348
348:         def eager_loader_key
349:           self[:eager_loader_key] ||= self[:left_primary_key]
350:         end

many_to_many associations need to select a key in an associated table to eagerly load

[Source]

     # File lib/sequel/model/associations.rb, line 353
353:         def eager_loading_use_associated_key?
354:           true
355:         end

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

[Source]

     # File lib/sequel/model/associations.rb, line 359
359:         def need_associated_primary_key?
360:           true
361:         end

Returns the reciprocal association symbol, if one exists.

[Source]

     # File lib/sequel/model/associations.rb, line 364
364:         def reciprocal
365:           return self[:reciprocal] if include?(:reciprocal)
366:           left_keys = self[:left_keys]
367:           right_keys = self[:right_keys]
368:           join_table = self[:join_table]
369:           associated_class.all_association_reflections.each do |assoc_reflect|
370:             if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
371:                assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
372:                assoc_reflect.associated_class == self[:model]
373:               return self[:reciprocal] = assoc_reflect[:name]
374:             end
375:           end
376:           self[:reciprocal] = nil
377:         end

The primary key column(s) to use in the associated table (can be symbol or array).

[Source]

     # File lib/sequel/model/associations.rb, line 380
380:         def right_primary_key
381:           self[:right_primary_key] ||= associated_class.primary_key
382:         end

The primary key columns to use in the associated table (always array).

[Source]

     # File lib/sequel/model/associations.rb, line 385
385:         def right_primary_keys
386:           self[:right_primary_keys] ||= Array(right_primary_key)
387:         end

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

[Source]

     # File lib/sequel/model/associations.rb, line 390
390:         def select
391:          return self[:select] if include?(:select)
392:          self[:select] ||= Sequel::SQL::ColumnAll.new(associated_class.table_name)
393:         end

[Validate]