コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
17809 ビュー

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.

アバター
破棄
最善の回答

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.

アバター
破棄
最善の回答

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?

アバター
破棄
最善の回答

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


 

 

アバター
破棄
関連投稿 返信 ビュー 活動
1
10月 18
5652
1
5月 15
8549
0
4月 15
3441
4
3月 15
11309
2
8月 25
2430