lib/activefacts/persistence/columns.rb in activefacts-0.7.1 vs lib/activefacts/persistence/columns.rb in activefacts-0.7.2
- old
+ new
@@ -57,49 +57,53 @@
end
# A Column name is a sequence of names (derived from the to_roles of the References)
# joined by a joiner string (pass nil to get the original array of names)
def name(joiner = "")
- last_name = ""
+ last_names = []
names = @references.
reject do |ref|
# Skip any object after the first which is identified by this reference
ref != @references[0] and
!ref.fact_type.is_a?(TypeInheritance) and
ref.to and
ref.to.is_a?(EntityType) and
- (role_refs = ref.to.preferred_identifier.role_sequence.all_role_ref).size == 1 and
- role_refs.only.role == ref.from_role
+ (role_ref = ref.to.preferred_identifier.role_sequence.all_role_ref.single) and
+ role_ref.role == ref.from_role
end.
inject([]) do |a, ref|
names = ref.to_names
# When traversing type inheritances, keep the subtype name, not the supertype names as well:
if a.size > 0 && ref.fact_type.is_a?(TypeInheritance)
- a[-1] = names[0] if ref.to == ref.fact_type.subtype # Else we already had the subtype
- next a
+ next a if ref.to != ref.fact_type.subtype # Did we already have the subtype?
+ last_names.size.times { a.pop } # Remove the last names added
+ elsif last_names.last && last_names.last == names[0][0...last_names.last.size]
+ # When Xyz is followed by XyzID, truncate that to just ID
+ names[0] = names[0][last_names.last.size..-1]
+ elsif last_names.last == names[0]
+ # Same, but where an underscore split up the words
+ names.shift
end
- # When Xyz is followed by XyzID, truncate that to just ID:
- names[0] = names[0][last_name.size..-1] if last_name == names[0][0...last_name.size]
- last_name = names.last
+ # Where the last name is like a reference mode but the preceeding name isn't the identified concept,
+ # strip it down (so turn Driver.PartyID into Driver.ID for example):
+ if a.size > 0 and
+ (et = ref.from).is_a?(EntityType) and
+ (role_ref = et.preferred_identifier.role_sequence.all_role_ref.single) and
+ role_ref.role == ref.to_role and
+ names[0][0...et.name.size].downcase == et.name.downcase
+ names[0] = names[0][et.name.size..-1]
+ names.shift if names[0] == ""
+ end
+ last_names = names
+
a += names
a
end
- # Where the last name is like a reference mode but the preceeding name isn't the identified concept,
- # strip it down (so turn Driver.PartyID into Driver.ID for example):
- if names.size > 1 and
- (et = @references.last.from).is_a?(EntityType) and
- (role_refs = et.preferred_identifier.role_sequence.all_role_ref).size == 1 and
- role_refs.only.role == @references.last.to_role and
- names.last[0...et.name.size].downcase == et.name.downcase
- names[-1] = names.last[et.name.size..-1]
- names.pop if names.last == ''
- end
-
name_array = names.map{|n| n.sub(/^[a-z]/){|s| s.upcase}}
joiner ? name_array * joiner : name_array
end
# Is this column mandatory or nullable?
@@ -183,13 +187,16 @@
module Metamodel #:nodoc:
# The Concept class is defined in the metamodel; full documentation is not generated.
# This section shows the features relevant to relational Persistence.
class Concept
# The array of columns for this Concept's table
- def columns; @columns; end
+ def columns
+ @columns
+ end
def populate_columns #:nodoc:
- @columns = all_columns({})
+ @columns =
+ all_columns({})
end
end
# The ValueType class is defined in the metamodel; full documentation is not generated.
# This section shows the features relevant to relational Persistence.