Class: MermaidRailsErd::RelationshipBuilders::HasOneRelationshipBuilder

Inherits:
BaseRelationshipBuilder show all
Defined in:
lib/mermaid_rails_erd/relationship_builders/has_one_relationship_builder.rb

Instance Attribute Summary

Attributes inherited from BaseRelationshipBuilder

#association_resolver, #model_data_collector, #symbol_mapper

Instance Method Summary collapse

Methods inherited from BaseRelationshipBuilder

#initialize

Constructor Details

This class inherits a constructor from MermaidRailsErd::RelationshipBuilders::BaseRelationshipBuilder

Instance Method Details

#build(model, assoc) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mermaid_rails_erd/relationship_builders/has_one_relationship_builder.rb', line 8

def build(model, assoc)
  from_table = model.table_name
  rel_type = symbol_mapper.map(assoc.macro)
  fk = safe_foreign_key(model, assoc)

  # Skip if we couldn't determine the foreign key
  return [] unless fk

  to_table_info = resolve_association_model(model, assoc)

  # Skip if this is a duplicate one-to-one relationship
  return [] if skip_duplicate_one_to_one?(model, assoc, to_table_info)

  if to_table_info
    [Relationship.new(
      from_table,
      to_table_info[:table_name],
      fk,
      rel_type,
      nil, # Let the Relationship generate the label
      to_table_info[:table_name], # fk_table
      fk, # fk_column
      from_table, # pk_table
      model.primary_key, # pk_column
    )]
  else
    log_missing_table_warning(model, assoc)
  end
end