Skip to content

Commit

Permalink
Review ORM compute decorator docs (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jun 24, 2021
1 parent baff432 commit 04247ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/orm/virtuals.md
Expand Up @@ -22,13 +22,15 @@ class Item(Model):
total = Field.float()

@compute('total')
def compute_total(self, row):
return row.price*row.quantity
def compute_total(self, fields):
return fields.price * fields.quantity
```

As you can see, the `compute` decorator needs and accepts just one parameter: the name of the field where to store the result of the computation.

The function that performs the computation has to accept the row as its first parameter, and it will be called both on inserts and updates.
The function that performs the computation has to accept the operation fields as its first parameter, and it will be called both on inserts and updates.

> **Note:** `compute` decorated methods receives **only the fields' values involved in the operation**. This means that fields will contain only the values passed by the insert/update operation and the relative default values.
Virtual attributes
------------------
Expand Down

0 comments on commit 04247ae

Please sign in to comment.