inheritance in list items

when accessing the ListCustomDetail property the sql is correctly assembled, but when accessing the ListDetail it gives sql error. am I mapping wrong or is it an error?

unit testeDetailHeranca;

interface

uses
Generics.Collections,
Aurelius.Mapping.Attributes, Aurelius.Types.Proxy
;

type
TDetail = class;
TCustomDetail = class;

[Entity, Automapping]
TMaster = class
private
FId: int64;
FNome: string;

[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FMaster')]
FListDetail: Proxy<TList<TDetail>>;

[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FMaster')]
FListCustomDetail: Proxy<TList<TCustomDetail>>;

function GetListDetail: TList<TDetail>;
function GetListCustomDetail: TList<TCustomDetail>;

public
constructor Create;
destructor Destroy; override;

property Id: int64 read FId write FId;
property Nome: string read FNome write FNome;
property ListDetail: TList<TDetail> read GetListDetail;
property ListCustomDetail: TList<TCustomDetail> read GetListCustomDetail;

end;

[Entity, Automapping]
[Inheritance(TInheritanceStrategy.JoinedTables)]
TCustomDetail = class
private
FId: int64;
FSeq: integer;
FMaster: Proxy;
function GetMaster: TMaster;
procedure SetMaster(const Value: TMaster);
public
property Id: int64 read FId write FId;
property Seq: integer read FSeq write FSeq;
property Master: TMaster read GetMaster write SetMaster;
end;

[Entity, Automapping]
TDetail = class(TCustomDetail)
private
FQtd: currency;
public
property Qtd: currency read FQtd write FQtd;
end;

[Entity, Automapping]
TDetail2 = class(TCustomDetail)
private
FQtd2: currency;
public
property Qtd2: currency read FQtd2 write FQtd2;
end;

implementation

{ TMaster }

constructor TMaster.Create;
begin
FListDetail.SetInitialValue(TList.Create);
FListCustomDetail.SetInitialValue(TList.Create);
end;

destructor TMaster.Destroy;
begin
FListCustomDetail.DestroyValue;
FListDetail.DestroyValue;
inherited Destroy;
end;

function TMaster.GetListCustomDetail: TList;
begin
Result := FListCustomDetail.Value;
end;

function TMaster.GetListDetail: TList;
begin
Result := FListDetail.Value;
end;

{ TCustomDetail }

function TCustomDetail.GetMaster: TMaster;
begin
Result := FMaster.Value;
end;

procedure TCustomDetail.SetMaster(const Value: TMaster);
begin
FMaster.Value := Value;
end;

end.

SQL when accessing ListDetail property:
SELECT A.ID AS A_ID, A.QTD AS A_QTD, B.ID AS B_ID, B.SEQ AS B_SEQ, B.MASTER_ID AS B_MASTER_ID
FROM DETAIL A
LEFT JOIN CUSTOM_DETAIL B ON (B.ID = A.ID)
WHERE A.MASTER_ID = :p_0

SQL when accessing ListCustomDetail property:
SELECT A.ID AS A_ID, A.SEQ AS A_SEQ, B.ID AS B_ID, B.QTD AS B_QTD, C.ID AS C_ID, C.QTD_2 AS C_QTD_2, A.MASTER_ID AS A_MASTER_ID
FROM CUSTOM_DETAIL A
LEFT JOIN DETAIL B ON (B.ID = A.ID)
LEFT JOIN DETAIL_2 C ON (C.ID = A.ID)
WHERE A.MASTER_ID = :p_0

Your mapping is indeed incorrect. You are mapping a list of TDetail objects, informing that the other side of association is FMaster, but the FMaster field doesn't belong to TDetail, thus is cannot be used.

in this case of inheritance it does not make sense to declare the FMaster property in TDetail and TDetail2

Unfortunately that's not how it works. It's db mapping, and we're talking about joined-tables hierarchy. So the "other side" of the association must be in the referenced table (the detail one, not custom detail).

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.