class ActiveFacts::Metamodel::ObjectType
The ObjectType
class is defined in the metamodel; full documentation is not generated. This section shows the features relevant to relational mapping.
Attributes
is_table[W]
Public Instance Methods
all_absorbed_foreign_key_reference_path()
click to toggle source
When an EntityType
is fully absorbed, its foreign keys are too. Return an Array of Reference paths for such absorbed FKs
# File lib/activefacts/rmap/foreignkey.rb, line 96 def all_absorbed_foreign_key_reference_path references_from.inject([]) do |array, ref| if ref.is_simple_reference if TypeInheritance === ref.fact_type # Ignore references to secondary supertypes, when absorption is through primary. next array if absorbed_via && TypeInheritance === absorbed_via.fact_type # Ignore the case where a subtype is absorbed elsewhere: # REVISIT: Disabled, as this should never happen. # next array if ref.to.absorbed_via != ref.fact_type end ref.fk_jump = true array << [ref] elsif ref.is_absorbing or (ref.to && !ref.to.is_table) trace :fk, "getting fks absorbed into #{name} via #{ref}" do ref.to.all_absorbed_foreign_key_reference_path.each do |aref| array << aref.insert(0, ref) end end end array end end
columns()
click to toggle source
The array of columns for this ObjectType’s table
# File lib/activefacts/rmap/columns.rb, line 255 def columns @columns || populate_columns end
foreign_keys()
click to toggle source
Return an array of all the foreign keys from this table
# File lib/activefacts/rmap/foreignkey.rb, line 124 def foreign_keys # Get the ForeignKey object for each absorbed reference path @foreign_keys ||= begin fk_ref_paths = all_absorbed_foreign_key_reference_path fk_ref_paths.map do |fk_ref_path| trace :fk, "\nFK: " + fk_ref_path.map{|fk_ref| fk_ref.reading }*" and " do from_columns = (columns||all_columns({})).select{|column| column.references[0...fk_ref_path.size] == fk_ref_path } trace :fk, "from_columns = #{from_columns.map { |column| column.name }*", "}" # Figure out absorption on the target end: to = fk_ref_path.last.to if to.absorbed_via trace :fk, "Reference target #{fk_ref_path.last.to.name} is absorbed via:" do while (r = to.absorbed_via) m = r.reversed trace :fk, "#{m.reading}" fk_ref_path << m to = m.from == to ? m.to : m.from end trace :fk, "Absorption ends at #{to.name}" end end # REVISIT: This test may no longer be necessary raise "REVISIT: #{fk_ref_path.inspect} is bad" unless to and to.columns # REVISIT: This fails for absorbed subtypes having their own identification. # Check the CompanyDirectorEmployee model for example, EmployeeManagerNr -> Person (should reference EmployeeNr) # Need to use the absorbed identifier_columns of the subtype, # not the columns of the supertype that absorbs it. # But in general, that isn't going to work because in most DBMS # there's no suitable uniquen index on the subtype's identifier_columns to_columns = fk_ref_path[-1].to.identifier_columns # Put the column pairs in the correct order. They MUST be in the order they appear in the primary key froms, tos = from_columns.zip(to_columns).sort_by { |pair| to_columns.index(pair[1]) }.transpose fk = ActiveFacts::RMap::ForeignKey.new(self, to, fk_ref_path, froms, tos) to.foreign_keys_to << fk fk end end. sort_by do |fk| # Put the foreign keys in a defined order: # debugger if !fk.to_columns || fk.to_columns.include?(nil) || !fk.from_columns || fk.from_columns.include?(nil) [ fk.to.name, fk.to_columns.map{|col| col.name(nil).sort}, fk.from_columns.map{|col| col.name(nil).sort} ] end end end
foreign_keys_to()
click to toggle source
# File lib/activefacts/rmap/foreignkey.rb, line 119 def foreign_keys_to @foreign_keys_to ||= [] end
indices()
click to toggle source
An array of each Index for this table
# File lib/activefacts/rmap/index.rb, line 106 def indices @indices || populate_indices end
references_from()
click to toggle source
References from this ObjectType
# File lib/activefacts/rmap/reference.rb, line 274 def references_from @references_from ||= [] end
references_to()
click to toggle source
References to this ObjectType
# File lib/activefacts/rmap/reference.rb, line 279 def references_to @references_to ||= [] end
wipe_columns()
click to toggle source
# File lib/activefacts/rmap/columns.rb, line 264 def wipe_columns @columns = nil end