class ActiveFacts::RMap::ForeignKey

Public Instance Methods

describe() click to toggle source
# File lib/activefacts/rmap/foreignkey.rb, line 30
def describe
  "foreign key from #{from.name}(#{from_columns.map{|c| c.name}*', '}) to #{to.name}(#{to_columns.map{|c| c.name}*', '})"
end
following_references() click to toggle source

Which references are absorbed into the “to” table?

# File lib/activefacts/rmap/foreignkey.rb, line 50
def following_references
  fk_jump = @references.detect(&:fk_jump)
  jump_index = @references.index(fk_jump)
  fk_jump != @references.last ? @references[jump_index+1..-1] : []
end
from() click to toggle source

What table (ObjectType) is the FK from?

# File lib/activefacts/rmap/foreignkey.rb, line 11
def from; @from; end
from_columns() click to toggle source

What columns in the from table form the FK

# File lib/activefacts/rmap/foreignkey.rb, line 20
def from_columns; @from_columns; end
from_name() click to toggle source

The from_name is the role name of the table with the FK, viewed from the other end When there are no precursor_references or following_references, it’s the jump_reference.from_names REVISIT: I’m still working out what to do with precursor_references and following_references

# File lib/activefacts/rmap/foreignkey.rb, line 72
def from_name
  p = precursor_references
  f = following_references
  j = jump_reference

  # pluralise unless j.is_one_to_one

  # REVISIT: references[0].from_names is where the FK lives; but the object of interest may be an absorbed subclass which we should use here instead:
  # REVISIT: Should crunch superclasses in subtype traversals
  # REVISIT: Need to add "_as_rolename" where rolename is not to.name

  [
    @references[0].from_names,
    (p.empty? && f.empty? ? [] : ['via'] + p.map{|r| r.to_names}.flatten + f.map{|r| r.from_names}.flatten)
  ]
end
jump_reference() click to toggle source
# File lib/activefacts/rmap/foreignkey.rb, line 56
def jump_reference
  @references.detect(&:fk_jump)
end
precursor_references() click to toggle source

Which references are absorbed into the “from” table?

# File lib/activefacts/rmap/foreignkey.rb, line 43
def precursor_references
  fk_jump = @references.detect(&:fk_jump)
  jump_index = @references.index(fk_jump)
  @references[0, jump_index]
end
references() click to toggle source

What reference created the FK?

# File lib/activefacts/rmap/foreignkey.rb, line 17
def references; @references; end
to() click to toggle source

What table (ObjectType) is the FK to?

# File lib/activefacts/rmap/foreignkey.rb, line 14
def to; @to; end
to_columns() click to toggle source

What columns in the to table form the identifier

# File lib/activefacts/rmap/foreignkey.rb, line 23
def to_columns; @to_columns; end
to_name() click to toggle source
# File lib/activefacts/rmap/foreignkey.rb, line 60
def to_name
  p = precursor_references
  f = following_references
  j = jump_reference

  @references.last.to_names +
    (p.empty? && f.empty? ? [] : ['via'] + p.map{|r| r.to_names}.flatten + f.map{|r| r.from_names}.flatten)
end
verbalised_path(reverse = false) click to toggle source
# File lib/activefacts/rmap/foreignkey.rb, line 34
def verbalised_path reverse = false
  # REVISIT: This should be a proper join path verbalisation:
  refs = reverse ? references.reverse : references
  refs.map do |r|
    r.verbalised_path reverse
  end * ' and '
end