I have a entity that can keep a list of itself (tree). Special case on an one-to-many association.
[Entity, Automapping]
[Table('Right')]
TRight = class(TObject)
strict private
FID: Integer;
[Association([TAssociationProp.Lazy], [])]
[JoinColumn('ID_Parent', [], 'ID')]
FParent: Proxy<TRight>;
FName: String;
FSubRights: TList<TRight>;
procedure SetID(const Value: Integer);
procedure SetName(const Value: String);
procedure SetParent(const Value: TRight);
private
function getParent: TRight;
public
constructor create; overload;
destructor destroy;
property Id: Integer read FID write SetID;
property Parent: TRight read getParent write SetParent;
property Name: String read FName write SetName;
[ManyValuedAssociation([], CascadeTypeAll, 'FParent')]
property SubRights: TList<TRight> read FSubRights write FSubRights;
end;
This creates this sqlite table
CREATE TABLE Right (
ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
ID_Parent INTEGER,
NAME TEXT NOT NULL,
SUB_RIGHTS_RIGHT_ID INTEGER,
CONSTRAINT FK_Right_Right_ID_Parent FOREIGN KEY (ID_Parent) REFERENCES Right (ID),
CONSTRAINT FK_Right_Right_SUB_RIGHTS_RIGH FOREIGN KEY (SUB_RIGHTS_RIGHT_ID) REFERENCES Right (ID))
Why Aurelius creates "SUB_RIGHTS_RIGHT_ID"-field?
The ManyValuedAssociation is mapped to the FParent-field.
And both fields are filled with the same values.
Is my entity-class correctly defined?