Why is TCustomerToAddress class is not an entity?
when I connect with the database(No rest datasnap) I can get the Address.
Connection is a firedac connection. I test it and I can get to Address.
procedure TForm1.Button6Click(Sender: TObject);
var
oItem: TCustomer;
oMng: TObjectManager;
begin
oMng:= TObjectManager.Create(Connection);
oItem:= oMng.Find<TCustomer>(edtCountryID.Text);
try
If assigned(oItem)
then begin
If oItem.CustomerToAddress.Count>0
then begin
self.Memo1.Lines.Add(format('%s (%d) : %d - %d - ALL: %s', [oItem.Name,
oItem.CustomerToAddress.Count,
oItem.ID,
oItem.CustomerToAddress.First.CustomerID,
oItem.CustomerToAddress.First.Address.StreetName]));
end;
If oItem.CustomerToAddress1.Count>0
then begin
self.Memo1.Lines.Add(format('%s (%d) : %d - %d - 1: %s', [oItem.Name,
oItem.CustomerToAddress1.Count,
oItem.ID,
oItem.CustomerToAddress1.First.CustomerID,
oItem.CustomerToAddress1.First.Address.StreetName]));
end;
If oItem.CustomerToAddress3.Count>0
then begin
self.Memo1.Lines.Add(format('%s (%d) : %d - %d - 3: %s', [oItem.Name,
oItem.CustomerToAddress3.Count,
oItem.ID,
oItem.CustomerToAddress3.First.CustomerID,
oItem.CustomerToAddress3.First.Address.StreetName]));
end;
end;
finally
oMng.Free;
end;
end;
I also change the class, but I can't get into the proxyloader in the Rest application.
Refactoring the TCustomerToAddress class:
[Entity]
[Table('CUSTOMERS2ADDRESSES')]
[Id('FCustomerID', TIdGenerator.None)]
[Id('FAddressID', TIdGenerator.None)]
[Id('FAddressTypeID', TIdGenerator.None)]
[UniqueKey('CUSTOMERID, ADDRESSID, ADDRESSTYPEID')]
[Inheritance(TInheritanceStrategy.SingleTable)] [DiscriminatorColumn('ADDRESSTYPEID', TDiscriminatorType.dtInteger)]
TCustomerToAddress = class (TBaseWithOutID)
private
[Column('CUSTOMERID', [TColumnProp.Required])]
FCustomerID: Integer;
[Column('ADDRESSID', [TColumnProp.Required])]
FAddressID: Integer;
[Column('ADDRESSTYPEID', [TColumnProp.Required])]
FAddressTypeID: Integer;
[Association([TAssociationProp.Lazy], CascadeTypeAll)]
[JoinColumn('ADDRESSID', [TColumnProp.Required])]
FAddress: Proxy<TAddress> ;
procedure SetCustomerID(const Value: Integer);
procedure SetAddressID(const Value: Integer);
procedure SetAddressTypeID(const Value: Integer);
procedure SetAddress(const Value: TAddress );
function GetAddress: TAddress;
public
property CustomerID: Integer read FCustomerID write SetCustomerID;
property AddressID: Integer read FAddressID write SetAddressID;
property AddressTypeID: Integer read FAddressTypeID write SetAddressTypeID;
property Address: TAddress read GetAddress write SetAddress;
end;
// [Entity]
// [Table('CUSTOMERS2ADDRESSES')]
//
// TCustomerToAddressWithDiscriminator = class(TCustomerToAddress)
//
// end;
[Entity]
[DiscriminatorValue(1)]
TCustomerToAddress1 = class(TCustomerToAddress)
end;
[Entity]
[DiscriminatorValue(3)]
TCustomerToAddress3 = class(TCustomerToAddress)
end;