Hi,
I believe that there is a bug in TObjectMap.HasIdValue when composite Ids are used. Consider the following definition:
[Entity]
[Table('projects')]
[Id('FId', TIdGenerator.Guid)]
TOrmProject = class(TOrmBase)
private
[Column('idproject', [TColumnProp.Required], 32)]
FId: string;
[Column('author', [], 255)]
FAuthor: Nullable<string>;
[Column('lockedby', [], 32)]
FLockedBy: Nullable<string>;
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FProject')]
FMeta: Proxy<TList<TOrmProjectmeta>>;
private // -- Methods
function GetMeta: TList<TOrmProjectmeta>;
public // -- Constructor and Destructor
constructor Create;
destructor Destroy; override;
public
property Id: string read FId write FId;
property Author: Nullable<string> read FAuthor write FAuthor;
property LockedBy: Nullable<string> read FLockedBy write FLockedBy;
// Other tables
property Meta: TList<TOrmProjectmeta> read GetMeta;
end;
[Entity]
[Table('projectsmeta')]
[Id('FKey', TIdGenerator.None)]
[Id('FProject', TIdGenerator.None)]
TOrmProjectmeta = class(TOrmBase)
private
[Column('key', [TColumnProp.Required], 255)]
FKey: string;
[Column('value', [TColumnProp.Lazy])]
FValue: Nullable<string>;
[Column('lockedby', [], 32)]
FLockedBy: Nullable<string>;
[Association([TAssociationProp.Lazy], [])]
[JoinColumn('idproject', [TColumnProp.NoUpdate], 'idproject')]
FProject: Proxy<TOrmProject>;
public
property Key: string read FKey write FKey;
property Value: Nullable<string> read FValue write FValue;
property LockedBy: Nullable<string> read FLockedBy write FLockedBy;
property Project: Proxy<TOrmProject> read FProject write FProject;
end;
The following code will try to Update ProjectsMeta instead of Insert, because it thinks that the ID field "Key" has been defined. But the Id field is a composite ID between "Key" and "Project":
// Create a new project
aProject := TOrmProject.Create();
aProject.Author := 'Sample Author';
// Create a new meta
aProjectMeta := TOrmProjectMeta.Create();
aProjectMeta.Key := 'aMetaKey';
aProjectMeta.Value := 'aMetaValue';
aProject.Meta.Add(aProjectMeta);
// Save everything
aProjectContainer.ObjectManager.Save(aProject);
What would be the work-around here ?
Node: This is a legacy DB so I can't add an ID to the ProjectsMeta table.
Thanks.