"Many relation" works as "one to one"

Probably I get a newbie error about relation design with xData
Using DataModeler + Aurelius + xData
DB = MySQL 8 using a MySQL 5.7 model

I create a relation like company / person with a foreign key between

When I create the first person (after creating a company entry) with relation to company using xData API using aurelius => All OK
with POST in Swagger as

  "FName": "John",
  "LName": "Doe",
  "company_id": {
    "company_id": 1

But when I create the second entry

  "FName": "Jeanne",
  "LName": "Doe",
  "company_id": {
    "company_id": 1

Response is OK but...
In DB the existing link between company an first person entry is switch from 1 to null.
The value of foreign key in "person" table is set to null for existing entry (before it was equal to ID of company, here 1)
It seems working a one-to-one relation, in place of one to many, breaking previous with new one.

By direct DB update or insert, one-to-many works fine, so I guess it's something at aurelius level definition (probably through Data Modeler generator)

Where to check please ?


Here part of Aurelius file about class with Association

  [ [Entity]
  [Id('Fcompany_id', TIdGenerator.IdentityOrSequence)]
  TCompany = class
    [Column('company_id', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    Fcompany_id: Integer;
    [Column('company_name', [], 64)]
    Fcompany_name: Nullable<string>;
    [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'Fcompany_id')]
    FPersonList: Proxy<TList<TPerson>>;
    function GetPersonList: TList<TPerson>;
    constructor Create;
    destructor Destroy; override;
    property company_id: Integer read Fcompany_id write Fcompany_id;
    property company_name: Nullable<string> read Fcompany_name write Fcompany_name;
    property PersonList: TList<TPerson> read GetPersonList;
  [Id('Fid_person', TIdGenerator.IdentityOrSequence)]
  TPerson = class
    [Column('id_person', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    Fid_person: Integer;
    [Column('FName', [], 50)]
    FFName: Nullable<string>;
    [Column('LName', [], 50)]
    FLName: Nullable<string>;
    [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('company_id', [], 'company_id')]
    Fcompany_id: Proxy<TCompany>;
    function Getcompany_id: TCompany;
    procedure Setcompany_id(const Value: TCompany);
    property id_person: Integer read Fid_person write Fid_person;
    property FName: Nullable<string> read FFName write FFName;
    property LName: Nullable<string> read FLName write FLName;
    property company_id: TCompany read Getcompany_id write Setcompany_id;

Your mapping is correct and it should behave as you expect. It makes no sense that it's clearing the company_id field in a totally unrelated person record.

I'm afraid I have to ask you to investigate more and if possible send steps to reproduce the issue, or maybe provide more details, as I believe the reason for the problem you are experiencing is not related to the info you provided here.