lib/activefacts/api/instance.rb in activefacts-api-1.1.0 vs lib/activefacts/api/instance.rb in activefacts-api-1.3.0

- old
+ new

@@ -50,12 +50,29 @@ @constellation.send(self.class.basename.to_sym) end # De-assign all functional roles and remove from constellation, if any. def retract + return unless constellation = @constellation + + unless constellation.loggers.empty? + # An object may have multiple identifiers, with potentially overlapping role sets + # Get one copy of each role to use in asserting the instance + if self.class.is_entity_type + identifying_role_values = {} + ([self.class]+self.class.supertypes_transitive).each do |klass| + klass.identifying_role_names.zip(identifying_role_values(klass)).each do |name, value| + identifying_role_values[name] = value + end + end + else + identifying_role_values = self + end + end + # Delete from the constellation first, while we remember our identifying role values - @constellation.deindex_instance(self) if @constellation + constellation.deindex_instance(self) instance_variable_set(@@constellation_variable_name ||= "@constellation", nil) # Now, for all roles (from this class and all supertypes), assign nil to all functional roles # The counterpart roles get cleared automatically. klasses = [self.class]+self.class.supertypes_transitive @@ -126,9 +143,12 @@ end instance_variable_set(role.variable, nil) end end end + + constellation.loggers.each{|l| l.call(:retract, self.class, identifying_role_values) } + end module ClassMethods #:nodoc: include ObjectType # Add Instance class methods here