I have a 1-many assosiation on TProjectTool -> TProjectToolModule.
What I would like to achive is that, when a TProjectTool is being inserted I'd like to manually add a TProjectToolModule as well.
I've dropped a TAureliusModelEvents component on my datamodule, and implemented the OnInserting event like this:
if Args.Entity is TProjectTool then begin
ProjectToolInserting(TObjectManager(Args.Manager), TProjectTool(Args.Entity));
end;
Then I have this procedure where I perform try to add the additional record in TProjectToolModule:
procedure TAppModelEvents.ProjectToolInserting(aManager: TObjectManager; aProjectTool: TProjectTool);
var
lProjectToolModule: TProjectToolModule;
begin
lProjectToolModule := TProjectToolModule.Create;
lProjectToolModule.ProjectToolID := aProjectTool;
lProjectToolModule.Name := 'Some name';
lProjectToolModule.SortNo := 0;
aManager.AddOwnership(lProjectToolModule);
//I've also tried aManager.Save(lProjectToolModule);
end;
All the code runs just fine without any exceptions, but my additional record (TProjectToolModule) is not being inserted. Any hints or suggestions as to what I'm doing wrong here?
Here are some snippets of my entities:
/* Snippet of ProjectTool entity
[Entity]
[Table('ProjectTool')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TProjectTool = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FID: Integer;
[Column('Name', [], 100)]
FName: Nullable<string>;
Snippet End */
/* Snippet of ProjectToolModule
[Entity]
[Table('ProjectToolModule')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TProjectToolModule = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FID: Integer;
[Column('Name', [], 100)]
FName: Nullable<string>;
[Column('SortNo', [])]
FSortNo: Nullable<Double>;
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ProjectToolID', [TColumnProp.Required], 'ID')]
FProjectToolID: Proxy<TProjectTool>;
Snippet End */