Kar
Kar

Reputation: 6365

Assign same value to an instance's attribute

If the attributes of an instance are assigned with the same value, would commit result in writes to the database? I just wonder whether it's good practice to update attributes without checking whether that the existing value is actually different to the new value.

Upvotes: 3

Views: 102

Answers (1)

tuomur
tuomur

Reputation: 7098

The ORM does value checks when flushing and creates updates only on changed values. Quoting the documentation:

At flush time, the value of each attribute is compared to its previously saved value, and if there’s no net change, no SQL operation will occur (this is a more expensive operation so it’s only done at flush time).

Upvotes: 3

Related Questions