C
C
codercat2016-03-13 16:04:35
Software design
codercat, 2016-03-13 16:04:35

Why get and update the entire model object when changing multiple fields?

I often see code like this:

id = params('id')
item = new Item(id)
item.somevalue = 'newValue'
item.save()

What is the point of first pulling the database to get the data, then overwriting all the fields when only 1-2 fields change?
To me, this looks like an extra step for convenience, but perhaps there are better reasons for doing an extra sample and a big update.
I assume that the update is still done by comparing the received model and the updated one, thereby generating an update request for only the changed fields, but then the question remains: why receive when you can simply update the necessary parameters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DarkMatter, 2016-03-13
@darkmatter

Because they are hostages of the ORM concept where work is carried out exclusively with objects https://ru.wikipedia.org/wiki/ORM and https://habrahabr.ru/post/237889/ i.e. the minimum category to sample is an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question