Access the foreign key column in the child table.

Hi.
I have a column declared in the master table as follows:

[ManyValuedAssociation([], CascadeTypeAllButRemove)]
[ForeignJoinColumn('ActionID', [])]
FFilesList : Proxy<TFilesList>;

How to access this column in the Details table at runtime since it is not visible in design time? I see that the column ActionID exists in the database.

Unfortunately I didn't understand your question.
If you are asking about TAureliusDataset, here is how to access detail records in a many-valued association:

Ok, let me try to explain better.
I have a master table Items defined like this:

  [Entity]
  [Table('Items')]
  [Description('')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TItem = class
  private
    [Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    [Description('')]
    FId: Integer;
    ...
    [ManyValuedAssociation([], CascadeTypeAllButRemove)]
    [ForeignJoinColumn('ItemID', [])]
    FFilesList : Proxy<TFilesList>;

And a detailed table Files:

TFilesList = TList;

  [Entity]
  [Table('File')]
  [Description('')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TFile = class
  private
    [Column('Id', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    [Description('')]
    FId: Integer;
    
    [Column('Description', [TColumnProp.Lazy])]
    [Description('')]
    FDescription: string;

    [Column('Name', [TColumnProp.Required, TColumnProp.Lazy])]
    [Description('')]
    FName: string;

The field ItemID is created in the Files table. My question is how to access this field? In particular, I need to get ItemID for a given Id inside the TFile class.
Something like this doesn't work:

  Result := FManager.Find<TItem>
    .Where(FDic.ID = FActionID)
    .List;

Because Result[0] doesn't contain field ItemID

You have to map the association as bidirectional, creating the other side of the association in the TFile class. There you create a Item: TItem association mapping and in the ManyValuedAssociation you modify it to point to that association:

    [ManyValuedAssociation([], CascadeTypeAllButRemove, 'FItem')]
    FFilesList : Proxy<TFilesList>;

It's explained here:

And here:

Ok, I tried to follow the documentation, and declared the association in the master table as follows:

[Entity]
[Table('Items')]     
TItem = class
     private
       [ManyValuedAssociation([], CascadeTypeAllRemoveOrphan, 'FItem')]
       FFilesList: Proxy<TFilesList>;

And in TFile:

TFilesList = TList<TFile>;

 [Table('Files')]
TFile = class
private    
     [Association([TAssociationProp.Lazy], [])]
     [JoinColumn('ItemID', [])]
     FItem: Proxy<TItem>;

It works. Thanks!

1 Like

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