Class: ActiveFacts::RMap::ForeignKey
- Inherits:
-
Object
- Object
- ActiveFacts::RMap::ForeignKey
- Defined in:
- lib/activefacts/rmap/foreignkey.rb
Instance Method Summary collapse
- #describe ⇒ Object
-
#following_references ⇒ Object
Which references are absorbed into the “to” table?.
-
#from ⇒ Object
What table (ObjectType) is the FK from?.
-
#from_columns ⇒ Object
What columns in the from table form the FK.
-
#from_name ⇒ Object
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.
-
#initialize(from, to, references, from_columns, to_columns) ⇒ ForeignKey
constructor
:nodoc:.
- #jump_reference ⇒ Object
-
#precursor_references ⇒ Object
Which references are absorbed into the “from” table?.
-
#references ⇒ Object
What reference created the FK?.
-
#to ⇒ Object
What table (ObjectType) is the FK to?.
-
#to_columns ⇒ Object
What columns in the to table form the identifier.
- #to_name ⇒ Object
- #verbalised_path(reverse = false) ⇒ Object
Constructor Details
#initialize(from, to, references, from_columns, to_columns) ⇒ ForeignKey
:nodoc:
25 26 27 28 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 25 def initialize(from, to, references, from_columns, to_columns) #:nodoc: @from, @to, @references, @from_columns, @to_columns = from, to, references, from_columns, to_columns end |
Instance Method Details
#describe ⇒ Object
30 31 32 |
# 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 ⇒ Object
Which references are absorbed into the “to” table?
50 51 52 53 54 |
# 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 ⇒ Object
What table (ObjectType) is the FK from?
11 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 11 def from; @from; end |
#from_columns ⇒ Object
What columns in the from table form the FK
20 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 20 def from_columns; @from_columns; end |
#from_name ⇒ Object
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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 ⇒ Object
56 57 58 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 56 def jump_reference @references.detect(&:fk_jump) end |
#precursor_references ⇒ Object
Which references are absorbed into the “from” table?
43 44 45 46 47 |
# 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 ⇒ Object
What reference created the FK?
17 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 17 def references; @references; end |
#to ⇒ Object
What table (ObjectType) is the FK to?
14 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 14 def to; @to; end |
#to_columns ⇒ Object
What columns in the to table form the identifier
23 |
# File 'lib/activefacts/rmap/foreignkey.rb', line 23 def to_columns; @to_columns; end |
#to_name ⇒ Object
60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
34 35 36 37 38 39 40 |
# 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 |