I try to post
{"supplier":{"id":"0004"}}
a supplier with id 0004 exists in db.
i get error AssociationReferencesTransientObject
Association references a transient object. \r\nParent: purchaseorder.entities.Tpurchaseorder(12157), Transient: supplier.entities.TSupplier(0004), Association: Fsupplier
Had to get up from bed to test this idea. And it worked.
So documenting it here for others / my team/and to dementic myself in future.
mark FSupplier with [transient]
Create addtional property Supplier:string read getSupplier write setsupplier; and mark that property with
[xdataProperty] .
In setsupplier just find correct supplier and assing it to FSupplier.value. Object manager can be found
TXDataOperationContext.Current.GetManager;
So only problem is what happens if some coder writes to supplier property to write without xdata ......
You shouldn't need to do all that. The problem you are getting is because you are missing the proper cascades in your association. I assume it was a mistake. Unless of course you have a good reason to not have any cascade in your mapping, in this case your solution is fine.
But if it's not case, you should just add TCascadeType.SaveUpdate and TCascadeType.Merge to the association. Or, even better, add all but remove, which is the recommended cascade for single associations:
Posting a new order with
..., "supplier" :{"id":"0004"} with CascadeTypeAllButRemove emptied all other fields of supplier
changed to Merge worked for me saved all existing data.
I assume that his is excepted behaviour
Using extra property with [xdataProperty] attribute makes it possible to present id in simplier format
"supplier": "0004".