Insert ManyValuedAssociation Error

I'm trying to Insert ManyValuedAssociation,
  [Entity]
  [Table('Wkt')]
  [Inheritance(TInheritanceStrategy.JoinedTables)]
  [Sequence('Id_Wkt')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TWkt = class
  private
    [Column('Id', [TColumnProp.Required])]
    FId: Int64;
    
    [ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FWktId')]
    FWktWStList: Proxy<TList<TWktWSt>>;
    function GetWktWStList: TList<TWktWSt>;
  public
    constructor Create;
    destructor Destroy; override;
    property Id: Int64 read FId write FId;
    property WktWStList: TList<TWktWSt> read GetWktWStList;
  end;

  [Entity]
  [Table('WktWSt')]
  [PrimaryJoinColumn('Id')]
  TWktWSt = class(TWktSet)
  private
    [Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('WktId', [TColumnProp.Required], 'Id')]
    FWktId: Proxy<TWkt>;
    function GetWktId: TWkt;
    procedure SetWktId(const Value: TWkt);
  public
    property WktId: TWkt read GetWktId write SetWktId;
  end;

  [Entity]
  [Table('WktSet')]
  [Inheritance(TInheritanceStrategy.JoinedTables)]
  [Sequence('Id_WktSet')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TWktSet = class
  private
    [Column('Id', [TColumnProp.Required])]
    FId: Int64;
   
    [Column('SetNumber', [TColumnProp.Required])]
    FSetNumber: integer;
  public
    property Id: Int64 read FId write FId;
    property SetNumber: integer read FSetNumber write FSetNumber;
  end;

  Manager.Merge(TWkt(NewDBObject));
  '[FireDAC][Phys][FB]validation error for column WKTID, value "*** null ***"'.

  How to save TWkt object? when TWkt already exist(update) merge is ok.
 
  thanks, Jofan
 

I have no idea what is and what contains NewDBObject, but the error says WKTID field is null, so you must fill it:


WktSt.WktId := SomeWktIdObject;


Hi,
   Yes, that's it, (sorry malformed JSON).
   I'm try to delete a line in a master-detail, using REST/JSON.
   How to delete a item on the detail(TWktWSt)?
   Ex: TWkt have 3 itmes on WktWStList, i need to delete item 2. If i merge TWkt without item 2, aurelius delete the item 2?
  

Yes, it does that if you use Merge.

Note that "delete" means just removing the item from the list. If you want to really delete, you must set TCascadeType.RemoveOrphan on that ManyValuedAssociation, or just delete the item directly which will obviously remove it from the list eventually.

Hi
  TCascadeType.RemoveOrphan, sorry, but where is that on DataModeler?
  thanks

There is no such option in Data Modeler, you have to add it manually.

Hi,

  Everyday I make changes in the database, export schema to aurelius and everyday i have to add attribute TCascadeType.RemoveOrphan?
  thanks

Hi,
 is it possible to add TCascadeType.RemoveOrphan in run time? I think its not possible add an attribute to field in runtime,but there is some Published directive?
 thanks, thanks, thanks

I make some fine turning after every Aurelius export from Data Modeler by calling FixMyORM.bat which is based on: http://www.dostips.com/forum/viewtopic.php?f=3&t=6044
Maybe you could use that also.

Yes, it's possible to do so. You can use methods from TMappingExplorer to retrieve a specific TAssociation object. You can do that in some ways:

Explorer := TMappingExplorer.Default; 
for Association in Explorer.GetAssociations(TMyClass, True, False) do ...
or
Association := Explorer.GetAssociationByMember(<TRttiMember instance>);
or
Association := Explorer.GetAssociationByPropertyName(TMyClass, 'FItems');

once you got Association object you can just modify it:

Association.Cascade := Association.Cascade + [TCascadeType.RemoveOrphan];

Hi,
  Thanks Wagner works like a charm.
  Thanks Hilanne, if you need something like that you should try Wagner suggestion.

Yes,Thanks. That's useful information to do some after export tailoring in the code.