I have read about associations but not sure if that is what I am looking as it seems quite weighty.
I have 2 objects (simplified here)
TLocation = class
ID: Integer;
Name: string;
Address: string;
end;
TEvent = class
ID: Integer;
Name: Integer;
Date: TDateTime;
LocationId: Integer;
end;
and I either want to add another field to TEvent or do a descendant which includes the linked TLocation.Name.
so either
TEvent = class
ID: Integer;
Name: Integer;
Date: TDateTime;
LocationId: Integer;
LocatioName: string;
end;
or
TEventEx = class(TEvent)
LocationName: String;
end;
What would be the easiest way and/or correct way to implement this in Aurelius?
Thanks.
wlandgraf
(Wagner Landgraf)
December 21, 2018, 12:46pm
2
The correct way is to create a property like this in TEvent:
TEvent = class
Location: TLocation;
It's the TLocation object associated with the TEvent. That way you always have all Location data accessible from Event:
Event.Location.Id;
Event.Location.Name;
is there an example of using this with the TXDataWebDataSet?
The music xdata-web example, doesn't map the Album.Artist this way.
Also, how do you select the sub fields for a grid?
Thanks
My definition is
[Association([TAssociationProp.Lazy],CascadeTypeAllButRemove)]
[JoinColumn('LOCATIONID', [])]
FLocation: TBuzzLocation;
and when I run the app I get
Project VCL_Buzz_XServer.exe raised exception class EAssertionFailed with message 'Field/property is not a Proxy<T> type (C:\DC\TMS Aurelius\source\core\Aurelius.Mapping.Explorer.pas, line 2341)'.
wlandgraf
(Wagner Landgraf)
January 3, 2019, 12:26pm
5
You have added [TAssociationProp.Lazy] flag to it indicating you want that association to be lazy-loaded, but you didn't declare the field as a proxy. You must either remove TAssociationProp.Lazy or declare FLocation as Proxy<TBuzzLocation> (recommended). Here is more info about it and sub properties:
Is the Invoice code used in the documentation available as a demo?
wlandgraf
(Wagner Landgraf)
March 3, 2019, 8:49pm
7
No but in the Music Library demo there is a similar entity with lazy-loaded list.