set attributes is not updated to database while calling save with patch option
See original GitHub issuehi all, I found that there is weird issue on save & set and the version of bookshelf.js is 0.10.3
// js code
const model = await Model.forge({ id: 5 }).fetch();
model.set('attr_a', 'some value');
await model.save({ attr_b: 'some value' }, { patch: true });
above operations only update attr_b to database.
In other ORM such as ruby’s ActiveRecord, it will update both attr_a & attr_b
// ruby code
model = Model.find(5);
model.attr_a = 'some value';
model.attr_b = 'some value';
model.save!
Does it make sense that changed attributes should be updated to database no matter what these attributes are changed by set or save method ?
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Django: save() vs update() to update the database?
But update() does not call save() on models. And if no save() method is called for update() , so the signals are not...
Read more >Different Ways to Set Attributes in ActiveRecord (Rails 4)
This method used to be called update_attributes in Rails 3. It changes the attributes of the model, checks the validations, and updates the ......
Read more >Update expressions - Amazon DynamoDB
An update expression specifies how UpdateItem will modify the attributes of an item—for example, setting a scalar value or removing elements from a...
Read more >Modifying data via the DbContext - Learn Entity Framework Core
When SaveChanges is called, an UPDATE statement is generated and executed by the database. var author = context.Authors.First( ...
Read more >ActiveRecord::Persistence - Rails API
Any change to the attributes on either instance will affect both instances. ... to the database. Only attribute is updated; the record itself...
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
patch: true
is really handy to avoid race condition if you have model updated in few places at the same time (happens for user entity pretty often) you can get some property overridden End up with my own attempt of implementing save fuctionality:The problem is if you call
set
thensave
withpatch: true
and check_previousAttributes
you’ll see old value, so all consequence call of minesaveModel
method fails. Maybe this can be fixed on library levelGot it. That helps, thanks.