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 410
410:         def associated_key_alias
411:           self[:left_key_alias]
412:         end

The column to use for the associated key when eagerly loading

[Source]

     # File lib/sequel/model/associations.rb, line 415
415:         def associated_key_column
416:           self[:left_key]
417:         end
associated_key_table()

Alias for join_table_alias

Alias of right_primary_keys

[Source]

     # File lib/sequel/model/associations.rb, line 420
420:         def associated_object_keys
421:           right_primary_keys
422:         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 426
426:         def can_have_associated_objects?(obj)
427:           !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
428:         end

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

[Source]

     # File lib/sequel/model/associations.rb, line 432
432:         def default_associated_key_alias
433:           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
434:         end

Default name symbol for the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 437
437:         def default_join_table
438:           [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
439:         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 443
443:         def default_left_key
444: 
445:           "#{underscore(demodulize(self[:model].name))}_id"
446:         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 449
449:         def default_right_key
450: 
451:           "#{singularize(self[:name])}_id"
452:         end

The key to use for the key hash when eager loading

[Source]

     # File lib/sequel/model/associations.rb, line 454
454:         def eager_loader_key
455:           self[:eager_loader_key] ||= self[:left_primary_key]
456:         end

The hash key to use for the eager loading predicate (left side of IN (1, 2, 3)). The left key qualified by the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 460
460:         def eager_loading_predicate_key
461:           self[:eager_loading_predicate_key] ||= qualify(join_table_alias, self[:left_key])
462:         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 471
471:         def eager_loading_use_associated_key?
472:           true
473:         end

The join table itself, unless it is aliased, in which case this is the alias.

[Source]

     # File lib/sequel/model/associations.rb, line 486
486:         def join_table_alias
487:           fetch(:join_table_alias) do
488:             split_join_table_alias
489:             self[:join_table_alias]
490:           end
491:         end

The source of the join table. This is the join table itself, unless it is aliased, in which case it is the unaliased part.

[Source]

     # File lib/sequel/model/associations.rb, line 477
477:         def join_table_source
478:           fetch(:join_table_source) do
479:             split_join_table_alias
480:             self[:join_table_source]
481:           end
482:         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 496
496:         def need_associated_primary_key?
497:           true
498:         end
qualified_left_key()

The right key qualified by the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 466
466:         def qualified_right_key
467:           self[:qualified_right_key] ||= qualify(join_table_alias, self[:right_key])
468:         end

right_primary_key qualified by the associated table

[Source]

     # File lib/sequel/model/associations.rb, line 517
517:         def qualified_right_primary_key
518:           self[:qualified_right_primary_key] ||= qualify_assoc(right_primary_key)
519:         end

Returns the reciprocal association symbol, if one exists.

[Source]

     # File lib/sequel/model/associations.rb, line 501
501:         def reciprocal
502:           return self[:reciprocal] if include?(:reciprocal)
503:           left_keys = self[:left_keys]
504:           right_keys = self[:right_keys]
505:           join_table = self[:join_table]
506:           associated_class.all_association_reflections.each do |assoc_reflect|
507:             if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
508:                assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
509:                assoc_reflect.associated_class == self[:model]
510:               return self[:reciprocal] = assoc_reflect[:name]
511:             end
512:           end
513:           self[:reciprocal] = nil
514:         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 522
522:         def right_primary_key
523:           self[:right_primary_key] ||= associated_class.primary_key
524:         end

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

[Source]

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

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

[Source]

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

[Validate]