Loopback: [BUG] Model with two `embedsMany` relations does not function properly

Created on 22 Jan 2017  路  1Comment  路  Source: strongloop/loopback

Bug

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)"]}}}}

Expected result

Both POSTs should work.

Additional information

Problem exists in 2.x loopback as well.

stale

Most helpful comment

I found a workaround that allows me to proceed: setting validate: false for embedsMany relations makes it work again.

>All comments

I found a workaround that allows me to proceed: setting validate: false for embedsMany relations makes it work again.

Was this page helpful?
0 / 5 - 0 ratings