lib/activefacts/generator/summary.rb in activefacts-compositions-1.9.17 vs lib/activefacts/generator/summary.rb in activefacts-compositions-1.9.18
- old
+ new
@@ -27,16 +27,18 @@
end
class Composite
def summary
indices = self.all_indices_by_rank
+ fks = {}
+ fk_count = 0
(
[mapping.name+"\n"] +
mapping.
all_leaf.
- reject{|leaf| leaf.is_a?(Absorption) && leaf.forward_absorption}.
+ reject{|leaf| leaf.is_a?(Absorption) && leaf.forward_mapping}.
flat_map do |leaf|
# Build a display of the names in this absorption path, with FK and optional indicators
path_names = leaf.path.map do |component|
is_mandatory = true
@@ -47,25 +49,32 @@
is_unique = component.parent_role.is_unique
when Indicator
is_mandatory = false
end
- if component.all_foreign_key_field.size > 0
- "[#{component.name}]"
- elsif component.is_a?(Absorption) && component.foreign_key
- "{#{component.name}}"
+ # if all_foreign_key.detect{|fk| fk.all_foreign_key_field.detect{|fkf| fkf.component == leaf}}
+ if component.is_a?(Mapping) && component.foreign_key && leaf.all_foreign_key_field.size > 0
+ fk_number = (fks[component.foreign_key] ||= (fk_count += 1))
+ "[F#{fk_number}:#{component.name}"
+ elsif component == leaf && leaf.all_foreign_key_field.size > 0
+ "#{component.name}]"
else
component.name
end +
(is_mandatory ? '' : '?') + (is_unique ? '' : '*')
end*'->'
# Build a symbolic representation of the index participation of this leaf
pos = 0
indexing = indices.inject([]) do |a, index|
+ # An index can be both Primary and Natural. Otherwise we show if it's Unique
+ type_str = ''
+ type_str << 'P' if index == primary_index
+ type_str << 'N' if index == natural_index
+ type_str = 'U' if type_str == '' && index.is_unique
pos += 1
if part = index.position_in_index(leaf)
- a << "#{pos}.#{part}"
+ a << "#{type_str}#{pos}" + (index.all_index_field.size > 1 ? ".#{part}" : "")
end
a
end
if indexing.empty?
indexing = ''