Save Entity with Foreign Key

Sorry, if this question is answered in the past. I have searched 30 minutes and found nothing.


I take the example from the help:
http://www.tmssoftware.biz/business/aurelius/doc/web/saving_objects.html

When I want to save a new invoice and I have only the Primary Key from the customer.
Can I save the invoice-record without load the customer-record? Without a TCustomer Object, only with Customer-ID

Yes and no. You should load the customer, that's the safest choice.



Invoice.Customer := Manager.Find<TCustomer>(15);
Manager.Save(Invoice);


However, there are ways to do what you want, but then you really need to know what you are doing, so you don't end up cleaning up all the customer properties. For example, this should work:


RefCustomer := TCustomer.Create;
RefCustomer.Id := 15;
Invoice.Customer := RefCustomer;
Manager.Save(Invoice);
RefCustomer.Free;


Wagner R. Landgraf2020-03-25 23:14:02

I suspected that, but haven't tried it yet.
;-)
Ok thanks