Hi
We have a problem with entities that has 'bidirectional' relationsships. We want to store each entity in a separate unit but then we cannot map a biderectional relationship without the circular referencs error.
We could omit the reference from the child to the mother but then we cant pass the child as a parameter and then access the mother.
consider the entities below where the mother has a many valued association to the child and the child doesnt have any association to the mother but we still want to have the mother id column (present in the child table in database) mapped as a pure integer.
This doesnt work thus aurelius when building the SQL adds the Mum column twice.
unit uEntityMother
uses
unit uEntityChild
TMother = class(TObject)
private
[Column('MumID' , [])]
fMumId: integer;
[ManyValuedAssociation([], CascadeTypeAllRemoveOrphan)]
[ForeignJoinColumn('Mum', [TColumnProp.Required])]
FChildren: TList<TChild>;
public
constructor Create;
destructor Destroy; override;
property MumId: Integer read fMumId;
property Children: TList<TChild> read FChildren write FChildren;
end;
unit uEntityChild
[Entity]
TChild = class(TObject)
private
[Column('ChildID' , [])]
fChildId: integer;
[Column('Mum' , [])]
FMum: Integer;
public
property ChildId: Integer read fChildId;
property Mum: Integer read FMum write FMum;
end;
The SQL will look something like this
CREATE TABLE CHILD ( ChildID INTEGER NOT NULL, Mum INTEGER NOT NULL, Mum INTEGER NOT NULL, CONSTRAINT PK_CHILD PRIMARY KEY (ChildID))
Thus containing the column Mum twice tough the many valued association in TMother.FChildren and the column TChild.FMum both maps to the same table and column in the database.
Is there anyway around this problem?
We really want to avoid putting a lot of entites in the same unit just to be able to map realations.
//Best regards