Loopback: embebs many updateById or set do not trigger database update

Created on 16 Feb 2016  路  15Comments  路  Source: strongloop/loopback

In a embedsMany relation with no "belongsTo" the method parent.item.create triggers a mongo update while the parent.item.set(id, newData), or parent.item.updateById(id, newData) don't.

This methods should also be better documented

bug stale

Most helpful comment

If anyone is attempting to use promises with this, it will not work. As soon as I switched it to the callback version, it worked.

All 15 comments

hey @mamartins I am trying to reproduce your issue, could you fork this sandbox and replace with your code? thanks.

sure! on it

@jannyHou here it is:
https://github.com/mamartins/loopback-sandbox

I have 3 methods, one creates, other creates and updates and one that just updates the embedsMany relation. All with same result.

@mamartins I am so sorry for replying you late, we have a deadline to pass so everything turns slow.

First in loopback we use updateAttribute and updateAttributes instead of parent.item.set(id, newData) to update data.
Please check doc for updating data to see more details. And also how to use updateAttribute & updateAttributes

Second I tried b.updateAttribute(property, value, cb) in a relation a hasMany b, b belongsTo a, the function works fine.
But the same function in relation a embedsMany b, b belongsTo a fails:

create new slot>>> { start: Mon Mar 21 2016 11:28:30 GMT-0400 (Eastern Daylight Time),
  id: 1 }
err>>> No slot found for id 1

I will upload my code later to reproduce it, I think it's a bug.
Thanks for your understanding:)


sandbox to reproduce error of updateAttributes:
https://github.com/jannyHou/loopback-sandbox/tree/bug/embedsMany-updateAttributes
I tried both mongodb and default memory, same error.
I am using the same models you provide in your sandbox:
Dayslots embedsMany Slots, Slots belongsTo Dayslots:

  1. npm install
  2. node .
  3. open explorer, try post /daySlots/createAndUpdateSlot, you will see error

if the relation is a one to many same happens

Any update on this. It seems like I am experience this bug.

Nothin works when trying to update a b in a embedsMany b. Tried all possible methods, set, updateById, updateAttribute, updateAttributes, updateAll.

The methods are not triggered, just hangs in there...

Found the problem. Not a bug at least in my use case.

The problem was a bug in my embedded model before save observer where next() was not being triggered.

more than one year and this is still a bug?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

If anyone is attempting to use promises with this, it will not work. As soon as I switched it to the callback version, it worked.

Will promise be ever supported to updateById?

If anyone is attempting to use promises with this, it will not work. As soon as I switched it to the callback version, it worked.

Experimenting the same issue here. Using the callback approach does work as expected.

Was this page helpful?
0 / 5 - 0 ratings