instance `save()` behavior when nothing has changed
See original GitHub issueHello,
How should I expect instance.save() to behave when invoked on an instance that has not been modified since load?
From http://docs.sequelizejs.com/en/latest/docs/instances/#updating-saving-persisting-an-instance:
When you call
savewithout changing any attribute, this method will execute nothing;
From http://docs.sequelizejs.com/en/latest/api/instance/#saveoptions-promisethiserrorsvalidationerror:
Validate this instance, and if the validation passes, persist it to the database.
From nodejs (sequelize 3.3.2):
> MyModel.findOne().then(s => s.save());
Executing (default): UPDATE "mymodels" SET "updated_at"='2015-08-15 02:06:57.325 +00:00' WHERE "id" = '3681e9f8-25a5-4863-9015-dd90d3a4a2e2'
If the intended behavior of save is indeed to not update the timestamp (when no fields have changed), how can I achieve that effect, in a future-proof way?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Why do my changes to model instances not get saved ...
The first method's changes get persisted when a save is called. The second method's changes do not get saved. I have noticed this...
Read more >Why doesn't Django's Model.save() save only the dirty fields ...
I've noticed that Model.save() will update all fields by default, which can introduce a lot of race conditions. If it update only the...
Read more >Tracking vs. No-Tracking Queries - EF Core | Microsoft Learn
Tracking behavior controls if Entity Framework Core will keep information ... instances and have those changes persisted by SaveChanges() .
Read more >Strange behavior in model.save() - Google Groups
You assign non saved instance to a meeting. Probably what happened internally is that place.pk is copied to meeting.place_id. > place.save().
Read more >Working with entity instances — Pony ORM documentation
All created instances belong to the current db_session() . In some object-relational mappers, you are required to call an object's save() method in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yeah, it seems the documentation needs to be cleared up a bit on this point.
It is intentional that nothing is saved if nothing has changed. You can manually mark a column as changed to force a save:
instance.changed('updatedAt', true)Okay. It really doesn’t seem like a documentation issue when I compare what you said with the observed behavior.
(nothing changed; something saved)