Objection.js: Why not always use .patch() instead of .update()?

Created on 19 Jun 2018  路  2Comments  路  Source: Vincit/objection.js

In the docs, .patch() is listed for partial updates, .update() for "whole objects."

So if I'm updating 9 of the 10 fields in an object, I guess I use .patch() - but then if I decide to update the last field too I refactor the code to use .update().

Why not just use .patch() all the time? It seems like unnecessary mental cycles to need to remember what .patch() and .update() are for.

We love this library, thanks!

Most helpful comment

You don't need to use update ever. Only use if you want to use json schema's required property.

All 2 comments

In my mind, it really comes down to consistency/validation. I think the short of it is this: use update() if you are replacing an entire record _and want to validate required attributes as being required_. Otherwise, use patch()! Admittedly I find myself using patch() much more often than update().

You don't need to use update ever. Only use if you want to use json schema's required property.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtlapp picture jtlapp  路  23Comments

vladshcherbin picture vladshcherbin  路  74Comments

koskimas picture koskimas  路  26Comments

amiuhle picture amiuhle  路  40Comments

krckyboy picture krckyboy  路  24Comments