Class: DbmlRelationsFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_to_dbml/dbml_relations_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(from_table:, to_table:, column: nil, on_delete: nil) ⇒ String

Formats a database relationship for a DBML file

Parameters:

  • from_table (String)

    the table that has the foreign key

  • to_table (String)

    the table being referenced

  • column (String, nil) (defaults to: nil)

    the name of the foreign key column; defaults to the singularized form of the to_table

  • on_delete (String, nil) (defaults to: nil)

    the delete behavior (e.g., “cascade”); optional

Returns:

  • (String)

    the formatted relationship string for a DBML file



14
15
16
17
18
19
20
21
22
# File 'lib/schema_to_dbml/dbml_relations_formatter.rb', line 14

def format(from_table:, to_table:, column: nil, on_delete: nil)
  column ||= default_foreign_key_column(to_table)

  ref_name = generate_reference_name(from_table, to_table, column)
  ref = build_reference_string(ref_name, from_table, column, to_table)

  format_on_delete(ref, on_delete)
  ref
end