#1 2017-01-24 11:17:44

Excalibur
Member
Registered: 2015-04-01
Posts: 5

OneToMany Relation with a different join field name (TSQLRecordMany)

I'm trying to implement an object view for a given database. With a single class and the mapping change via .ExternalDB.MapField I found the way to grab records and store them back with their internal database key field. Also the loading of a "list" of objects with CreateAndFillPrepare / .FillOne and a wider select works fine (i.e. load all TDest).

So now I want to include one class into another, because in database it is a sub table and I want the sub class to be autoloaded, if the top class is loaded.

type
  TDest = class;
  TSource = class;

  TDests = class(TSQLRecordMany)
  ..
    property Source: TSource..
    property Dest: TDest...
...
  TSource = class(TSQLRecord)
    property Destinations: TDests read fDestinations;
  end;

  VirtualTableExternalRegister(Model, TDest, aConnProps, 'D_TABLE_DEST);
  VirtualTableExternalRegister(Model, TSource, aConnProps, 'D_TABLE_SRC');

  Model.Props[TDest].ExternalDB.MapField('ID', 'D_DST_ID');
  Model.Props[TDests].ExternalDB.MapField('ID', 'D_DST_ID');
  Model.Props[TSource].ExternalDB.MapField('ID', 'D_SRC_ID');

The TDests object is created in constructor of TSource. But the linking between the two tables is not done via a ManyToMany table inbetween. The TDest table has a column which refers to the source table (ID_SRC_TABLE). Did I have a chance to modify the autoconstructed joins and tell the created model, that the field "D_DST_SRC_ID" should be used to identify all TDest(s) and load them into Destinations within the loading/creating a TSource?

Maybe this is a very simple thing to do, but I'm looking for a solution now several hours without finding an answer. All examples I've found in the SQLLite3\Samples are using the auto mechanism for joining. If I run the server with this shorten example I always getting the error message "TDests expects a SOURCE field" - so I'm searching where to set it correctly.

Last edited by Excalibur (2017-01-24 11:20:06)

Offline

Board footer

Powered by FluxBB