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

### Methods

associated_key_alias associated_key_column associated_key_table associated_object_keys can_have_associated_objects? default_associated_key_alias default_join_table default_left_key default_right_key eager_loader_key eager_loading_predicate_key eager_loading_use_associated_key? join_table_alias join_table_source need_associated_primary_key? qualified_left_key qualified_right_key qualified_right_primary_key reciprocal right_primary_key right_primary_key_method right_primary_key_methods right_primary_keys select

### Public Instance methods

associated_key_alias()

The alias to use for the associated key when eagerly loading

[Source]

         # File lib/sequel/model/associations.rb, line 422
    422:         def associated_key_alias
    423:           self[:left_key_alias]
    424:         end

associated_key_column()

The column to use for the associated key when eagerly loading

[Source]

         # File lib/sequel/model/associations.rb, line 427
    427:         def associated_key_column
    428:           self[:left_key]
    429:         end

associated_key_table()

Alias for join_table_alias

associated_object_keys()

Alias of right_primary_keys

[Source]

         # File lib/sequel/model/associations.rb, line 432
    432:         def associated_object_keys
    433:           right_primary_keys
    434:         end

can_have_associated_objects?(obj)

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 438
    438:         def can_have_associated_objects?(obj)
    439:           !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
    440:         end

default_associated_key_alias()

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

[Source]

         # File lib/sequel/model/associations.rb, line 444
    444:         def default_associated_key_alias
    445:           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
    446:         end

default_join_table()

Default name symbol for the join table.

[Source]

         # File lib/sequel/model/associations.rb, line 449
    449:         def default_join_table
    450:           [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
    451:         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/associations.rb, line 455
    455:         def default_left_key
    456:
    457:           "#{underscore(demodulize(self[:model].name))}_id"
    458:         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/associations.rb, line 461
    461:         def default_right_key
    462:
    463:           "#{singularize(self[:name])}_id"
    464:         end

eager_loader_key()

The key to use for the key hash when eager loading

[Source]

         # File lib/sequel/model/associations.rb, line 466
    466:         def eager_loader_key
    467:           self[:eager_loader_key] ||= self[:left_primary_key]
    468:         end

eager_loading_predicate_key()

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 472
    472:         def eager_loading_predicate_key
    473:           self[:eager_loading_predicate_key] ||= qualify(join_table_alias, self[:left_key])
    474:         end

eager_loading_use_associated_key?()

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

[Source]

         # File lib/sequel/model/associations.rb, line 483
    483:         def eager_loading_use_associated_key?
    484:           true
    485:         end

join_table_alias()

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

[Source]

         # File lib/sequel/model/associations.rb, line 498
    498:         def join_table_alias
    499:           fetch(:join_table_alias) do
    500:             split_join_table_alias
    501:             self[:join_table_alias]
    502:           end
    503:         end

join_table_source()

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 489
    489:         def join_table_source
    490:           fetch(:join_table_source) do
    491:             split_join_table_alias
    492:             self[:join_table_source]
    493:           end
    494:         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/associations.rb, line 508
    508:         def need_associated_primary_key?
    509:           true
    510:         end

qualified_left_key()

Alias for eager_loading_predicate_key

qualified_right_key()

The right key qualified by the join table.

[Source]

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

qualified_right_primary_key()

right_primary_key qualified by the associated table

[Source]

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

reciprocal()

Returns the reciprocal association symbol, if one exists.

[Source]

         # File lib/sequel/model/associations.rb, line 513
    513:         def reciprocal
    514:           return self[:reciprocal] if include?(:reciprocal)
    515:           left_keys = self[:left_keys]
    516:           right_keys = self[:right_keys]
    517:           join_table = self[:join_table]
    518:           associated_class.all_association_reflections.each do |assoc_reflect|
    519:             if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
    520:                assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
    521:                assoc_reflect.associated_class == self[:model]
    522:               return self[:reciprocal] = assoc_reflect[:name]
    523:             end
    524:           end
    525:           self[:reciprocal] = nil
    526:         end

right_primary_key()

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

[Source]

         # File lib/sequel/model/associations.rb, line 534
    534:         def right_primary_key
    535:           self[:right_primary_key] ||= associated_class.primary_key
    536:         end

right_primary_key_method()

The method symbol or array of method symbols to call on the associated objects to get the foreign key values for the join table.

[Source]

         # File lib/sequel/model/associations.rb, line 545
    545:         def right_primary_key_method
    546:           self[:right_primary_key_method] ||= right_primary_key
    547:         end

right_primary_key_methods()

The array of method symbols to call on the associated objects to get the foreign key values for the join table.

[Source]

         # File lib/sequel/model/associations.rb, line 551
    551:         def right_primary_key_methods
    552:           self[:right_primary_key_methods] ||= Array(right_primary_key_method)
    553:         end

right_primary_keys()

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

[Source]

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

select()

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

[Source]

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

[Validate]