balderdashy / waterline-docs

WARNING: The content in this repo is out of date! See https://github.com/balderdashy/sails-docs for the most up-to-date documentation
452 stars 163 forks source link

document that save() can clobber values #80

Open kevinburkeshyp opened 9 years ago

kevinburkeshyp commented 9 years ago

say you have two threads which both have a User object in memory. one updates the email, the other updates the phone number. both call save(). this turns into

UPDATE users set email=newemail, phonenumber=oldphonenumber, ...
UPDATE users set email=oldemail, phonenumber=newnumber, ...

both threads believe they've saved the new value on the object, however, one of the updates got clobbered by the other one.

probably no plan to fix this behavior, might at least want to document it & explain that you probably want to do an UPDATE w/ only the affected property(ies) if you care about the consistency of your data.

tjwebb commented 9 years ago

Yea, this is a typical race condition that probably needs to just be handled like any other synchronization concern. An UPDATE will still overwrite any values that are specified in the provided "update" object.

kevinburkeshyp commented 9 years ago

Right, but with an UPDATE usually I'm specifying the columns I want to overwrite/clobber. With save() it's implicit, it's easier to miss. For what it's worth I didn't realize the implications for ~5 months of using the ORM

dmarcelino commented 9 years ago

@kevinburkeshyp, PR balderdashy/waterline#1048 should fix this behaviour where only changed fields actually get sent to the DB on .save().