Module: Dart::NamingConventions::ManyToManyAssociationHelpers

Includes:
AssociationHelpers
Included in:
Database::ManyToManyAssociation
Defined in:
lib/dart/naming_conventions/many_to_many_association_helpers.rb

Instance Method Summary collapse

Methods included from AssociationHelpers

#naming_conventions, #set_conventional_name!

Instance Method Details

#conventional_nameString

Returns the name of a referenced association according to the naming convention

Returns:

  • (String)

    the name of the referenced association



10
11
12
13
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 10

def conventional_name
  # just return e.g. 'groups' if right_ass.foreign_key is group_id
  naming_conventions.plural_association_name(right_ass.foreign_key)
end

#disambiguate_name!Object

forces long-form name to disambiguate from other joins to same association, where short-form name is the same



33
34
35
36
37
38
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 33

def disambiguate_name!
  unless is_semi_conventional_join_table?
    # add a foreign_key disambiguator when the key referencing me is unconventional
    set_name! naming_conventions.long_association_name(join_table, left_ass.foreign_key, left_ass.parent_table, right_ass.foreign_key)
  end
end

#left_foreign_key_is_conventional?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 24

def left_foreign_key_is_conventional?
  left_ass.conventional_foreign_key?
end

#name_and_right_foreign_key_are_conventional?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 19

def name_and_right_foreign_key_are_conventional?
  # name == associated_table == naming_conventions.parent_table_for(right_ass.foreign_key)
  name_is_conventional? && right_foreign_key_is_conventional?
end

#name_is_conventional?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 15

def name_is_conventional?
  name == associated_table
end

#right_foreign_key_is_conventional?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dart/naming_conventions/many_to_many_association_helpers.rb', line 28

def right_foreign_key_is_conventional?
  right_ass.conventional_foreign_key?
end