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[:associated_key_table] ||= (
311:           syms = associated_class.dataset.split_alias(self[:join_table]);
312:           syms[1] || syms[0])
313:         end

Alias of right_primary_keys

[Source]

     # File lib/sequel/model/associations.rb, line 316
316:         def associated_object_keys
317:           right_primary_keys
318:         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 322
322:         def can_have_associated_objects?(obj)
323:           !self[:left_primary_keys].any?{|k| obj.send(k).nil?}
324:         end

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

[Source]

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

Default name symbol for the join table.

[Source]

     # File lib/sequel/model/associations.rb, line 333
333:         def default_join_table
334:           [self[:class_name], self[:model].name].map{|i| underscore(pluralize(demodulize(i)))}.sort.join('_').to_sym
335:         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 339
339:         def default_left_key
340: 
341:           "#{underscore(demodulize(self[:model].name))}_id"
342:         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 345
345:         def default_right_key
346: 
347:           "#{singularize(self[:name])}_id"
348:         end

The key to use for the key hash when eager loading

[Source]

     # File lib/sequel/model/associations.rb, line 350
350:         def eager_loader_key
351:           self[:eager_loader_key] ||= self[:left_primary_key]
352:         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 355
355:         def eager_loading_use_associated_key?
356:           true
357:         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 361
361:         def need_associated_primary_key?
362:           true
363:         end

Returns the reciprocal association symbol, if one exists.

[Source]

     # File lib/sequel/model/associations.rb, line 366
366:         def reciprocal
367:           return self[:reciprocal] if include?(:reciprocal)
368:           left_keys = self[:left_keys]
369:           right_keys = self[:right_keys]
370:           join_table = self[:join_table]
371:           associated_class.all_association_reflections.each do |assoc_reflect|
372:             if assoc_reflect[:type] == :many_to_many && assoc_reflect[:left_keys] == right_keys &&
373:                assoc_reflect[:right_keys] == left_keys && assoc_reflect[:join_table] == join_table &&
374:                assoc_reflect.associated_class == self[:model]
375:               return self[:reciprocal] = assoc_reflect[:name]
376:             end
377:           end
378:           self[:reciprocal] = nil
379:         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 382
382:         def right_primary_key
383:           self[:right_primary_key] ||= associated_class.primary_key
384:         end

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

[Source]

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

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

[Source]

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

[Validate]