A model with two embedsMany relations, for example a customer with many addresses and many emails, does not work properly. You can't add an address and then an email. Simple steps to reproduce below.
git clone [email protected]:strongloop/loopback-example-relations.git
Edit common/models/customer.json and change emails relation to be of "type": "embedsMany".
Now start the app and customer model is not really functional. Cannot add even a single email after adding an address. For example:
npm start
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{}" "http://localhost:3000/api/Customers/1/address"
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{}" "http://localhost:3000/api/Customers/1/emails"
results in following error
{"error": {"statusCode":422,"name":"ValidationError",
"message": "The `Customer` instance is not valid. Details: `billingAddress` contains invalid item: `4425d5cd30756105b3ead597` (`id` can't be set) (value: [ { street: undefined,\n ...} ]).",
"details": {"context":"Customer","codes":{"billingAddress":["invalid"]},
"messages": {"billingAddress":["contains invalid item: `4425d5cd30756105b3ead597` (`id` can't be set)"]}}}}
Both POSTs should work.
Problem exists in 2.x loopback as well.
I found a workaround that allows me to proceed: setting validate: false for embedsMany relations makes it work again.
Most helpful comment
I found a workaround that allows me to proceed: setting
validate: falseforembedsManyrelations makes it work again.