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 310
310:         def associated_key_alias
311:           self[:left_key_alias]
312:         end

The column to use for the associated key when eagerly loading

[Source]

     # File lib/sequel/model/associations.rb, line 315
315:         def associated_key_column
316:           self[:left_key]
317:         end

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

[Source]

     # File lib/sequel/model/associations.rb, line 320
320:         def associated_key_table
321:           self[:associated_key_table] ||= (
322:           syms = associated_class.dataset.split_alias(self[:join_table]);
323:           syms[1] || syms[0])
324:         end

Alias of right_primary_keys

[Source]

     # File lib/sequel/model/associations.rb, line 327
327:         def associated_object_keys
328:           right_primary_keys
329:         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 333
333:         def can_have_associated_objects?(obj)
334:           !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
335:         end

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

[Source]

     # File lib/sequel/model/associations.rb, line 339
339:         def default_associated_key_alias
340:           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
341:         end

Default name symbol for the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 344
344:         def default_join_table
345:           [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
346:         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 350
350:         def default_left_key
351: 
352:           "#{underscore(demodulize(self[:model].name))}_id"
353:         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 356
356:         def default_right_key
357: 
358:           "#{singularize(self[:name])}_id"
359:         end

The key to use for the key hash when eager loading

[Source]

     # File lib/sequel/model/associations.rb, line 361
361:         def eager_loader_key
362:           self[:eager_loader_key] ||= self[:left_primary_key]
363:         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 366
366:         def eager_loading_use_associated_key?
367:           true
368:         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 372
372:         def need_associated_primary_key?
373:           true
374:         end

Returns the reciprocal association symbol, if one exists.

[Source]

     # File lib/sequel/model/associations.rb, line 377
377:         def reciprocal
378:           return self[:reciprocal] if include?(:reciprocal)
379:           left_keys = self[:left_keys]
380:           right_keys = self[:right_keys]
381:           join_table = self[:join_table]
382:           associated_class.all_association_reflections.each do |assoc_reflect|
383:             if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
384:                assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
385:                assoc_reflect.associated_class == self[:model]
386:               return self[:reciprocal] = assoc_reflect[:name]
387:             end
388:           end
389:           self[:reciprocal] = nil
390:         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 393
393:         def right_primary_key
394:           self[:right_primary_key] ||= associated_class.primary_key
395:         end

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

[Source]

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

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

[Source]

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

[Validate]