Module: RDBr::Metadata::Relationships

Includes:
RelationshipInference
Included in:
Database
Defined in:
lib/rdbr/metadata/relationships.rb

Constant Summary

Constants included from RelationshipInference

RDBr::Metadata::RelationshipInference::INTEGER_TYPES

Instance Method Summary collapse

Instance Method Details

#incoming_relationships(namespace, relation) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rdbr/metadata/relationships.rb', line 22

def incoming_relationships(namespace, relation)
  relationship_candidates.filter_map do |source_namespace, source_relation, foreign_key, inferred|
    next unless reference_matches?(source_namespace, foreign_key, namespace, relation)

    DirectRelationship.new(
      source_namespace: source_namespace, source_relation: source_relation,
      target_namespace: namespace, target_relation: relation, foreign_key: foreign_key, inferred: inferred
    )
  end.freeze
end

#outgoing_relationships(namespace, relation) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rdbr/metadata/relationships.rb', line 14

def outgoing_relationships(namespace, relation)
  relationship_candidates.filter_map do |source_namespace, source_relation, foreign_key, inferred|
    next unless source_namespace == namespace && source_relation == relation

    direct_relationship(source_namespace, source_relation, foreign_key, inferred)
  end.freeze
end

#through_relationships(namespace, relation) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rdbr/metadata/relationships.rb', line 33

def through_relationships(namespace, relation)
  relationship_candidates.filter_map do |junction_namespace, junction_relation, source_foreign_key, inferred|
    next unless reference_matches?(junction_namespace, source_foreign_key, namespace, relation)

    through_relationships_from(
      junction_namespace, junction_relation, source_foreign_key, namespace, relation, inferred
    )
  end.flatten.freeze
end