Skip to Content
Menu
This question has been flagged
3 Replies
16493 Views

So, I was learning Odoo ORM,


There are 4 methods which make me confused:

- create & new

- write & update


In my point of view, they are doing the same thing: create and new create new record, update and write altering that record data. But if they did the same thing, why needed both?

Can anyone give me the answer. Thank you so much for your help, you don't know how much I wanted this answer.

Avatar
Discard
Best Answer

Create Method: The create method creates new records. It takes a dictionary of values, applies any defaults we have specified and then inserts the record an returns the new ID.

New Method: Return a new record instance attached to the current environment and initialized with the provided `value`. The record is *not* created in database, it only exists in memory.

**************************************************************************************

Write Method:The write method updates existing records. It takes a dictionary of values and applies to all of the ids you pass. if you pass a list of ids, the values will be written to all ids. For updating a single record, pass a list of one entry, if you want to do different updates to the records, you have to do multiple write calls. You can also manage related fields with a write.

Update Method: Write do not work for records set which are not present in the database. Onchange method returns pseudo-records which do not exist in the database yet. So set record's field using update() method as calling write() method gives an undefined behavior.

Avatar
Discard
Best Answer

In addition to the described differences between Create/New and the Write/Update methods, could you please clarify the differences between Delete/Remove/Unlink? Which one is used for in memory (pseudo records) and database?

Avatar
Discard
Best Answer

It seems you are confused about the term related to ORM methods and UI button eg. 'Create'

CRUD is common for MODELs operations

Create, Read, Update, and Delete (CRUD) are the four basic functions that models should be able to do, at most.

For more details for Odoo ORM  you can refer the below link

https://www.odoo.com/documentation/14.0/reference/orm.html#common-orm-methods


 

 

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 18
5049
1
May 15
7858
0
Apr 15
2902
4
Mar 15
10715
2
Apr 25
2122