Hi,
Please consider the following code:
LSchematic := SchematicFromNode(LNodeSchematic); // LSchematic is a TSchematic entity
LSettings := SettingsFromNode(LNodeSettings); // LSettings is a TSettings entity
try
LSchematic.Settings := LSettings; // Set the "association field"
LSchematicResult := FObjMgr.Replicate(LSchematic); // Replicate. Schematic entity (ID) may already exist
FObjMgr.Flush; // Ensure all written to database
SchematicID := LSchematicResult.ID; // Return ID. Used to update UI.
finally
if not FObjMgr.IsAttached(LSettings) then
LSettings.Free; // *** THIS CODE IS ALWAYS EXECUTED
LSchematic.Free;
end;
When I Replicate the TSchematic - together with the TSettings entity (!!) - and then Flush the ObjectManager, both entities are correctly persisted to the database. Yet the TSettings entity is not attached to the ObjectManager.
This doesn't make sense to me; I would expect that - if the TSettings is persisted together with the TSchematic (by association) - both entities would be attached to the ObjectManager after the Flush operation.
What am I missing? Does Replicate also spawn a new TSettings entity (by association) which is attached to the ObjectManager?
Rgds, Mark