class ActiveFacts::Metamodel::EntityType

The EntityType class is defined in the metamodel; full documentation is not generated. This section shows the features relevant to relational mapping.

Public Instance Methods

identifier_columns() click to toggle source

The identifier_columns for an EntityType are the columns that result from the identifying roles

# File lib/activefacts/rmap/columns.rb, line 331
def identifier_columns
  trace :columns, "Identifier Columns for #{name}" do
    if absorbed_via and
      # If this is a subtype that has its own identification, use that instead
      (all_type_inheritance_as_subtype.size == 0 ||
        all_type_inheritance_as_subtype.detect{|ti| ti.provides_identification })
      return absorbed_via.from.identifier_columns
    end

    preferred_identifier.role_sequence.all_role_ref.map do |role_ref|
      ref = references_from.detect {|ref| ref.to_role == role_ref.role}

      columns.select{|column| column.references[0] == ref}
    end.flatten
  end
end
is_table() click to toggle source

Returns true if this EntityType is a table

# File lib/activefacts/rmap/tables.rb, line 60
def is_table
  return @is_table if @is_table != nil  # We already make a guess or decision

  @tentative = false

  # Always a table if marked so
  if is_separate
    trace :absorption, "EntityType #{name} is declared independent or separate"
    return @is_table = true
  end

  # Always a table if nowhere else to go, and has no one-to-ones that might flip:
  if references_to.empty? and
      !references_from.detect{|ref| ref.role_type == :one_one }
    trace :absorption, "EntityType #{name} is presumed independent as it has nowhere to go"
    return @is_table = true
  end

  # Subtypes may be partitioned or separate, in which case they're definitely tables.
  # Otherwise, if their identification is inherited from a supertype, they're definitely absorbed.
  # If they have separate identification, it might absorb them.
  if (!supertypes.empty?)
    as_ti = all_supertype_inheritance.detect{|ti| ti.assimilation}
    @is_table = as_ti != nil
    if @is_table
      trace :absorption, "EntityType #{name} is #{as_ti.assimilation} from supertype #{as_ti.supertype}"
    else
      identifying_fact_type = preferred_identifier.role_sequence.all_role_ref.to_a[0].role.fact_type
      if identifying_fact_type.is_a?(TypeInheritance)
        trace :absorption, "EntityType #{name} is absorbed into supertype #{supertypes[0].name}"
        @is_table = false
      else
        # Possibly absorbed, we'll have to see how that pans out
        @tentative = true
      end
    end
    return @is_table
  end

  # If the preferred_identifier includes an auto_assigned ValueType
  # and this object is absorbed in more than one place, we need a table
  # to manage the auto-assignment.
  if references_to.size > 1 and
    preferred_identifier.role_sequence.all_role_ref.detect {|rr|
      next false unless rr.role.object_type.is_a? ValueType
      rr.role.object_type.is_auto_assigned
    }
    trace :absorption, "#{name} has an auto-assigned counter in its ID, so must be a table"
    @tentative = false
    return @is_table = true
  end

  @tentative = true
  @is_table = true
end
self_index() click to toggle source
# File lib/activefacts/rmap/index.rb, line 87
def self_index
  nil
end