2015-08-18 26 views

回答

2

我終於找到了答案ORM寫入方法。

  • 對於many2many字段,預計會有一個元組列表。 下面是被接受的元組的列表中,與相應的語義::

      (0, 0, { values }) link to a new record that needs to be created with the given values dictionary 
         (1, ID, { values }) update the linked record with id = ID (write *values* on it) 
         (2, ID)    remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) 
         (3, ID)    cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself) 
         (4, ID)    link to existing record with id = ID (adds a relationship) 
         (5)     unlink all (like using (3,ID) for all linked records) 
         (6, 0, [IDs])   replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs) 
    

實施例: [(6,0,[8,5,6,4])]設置many2many到ID [8,5,6,4]

  • 對於one2many字段,預計會有一些元組。 下面是被接受的元組的列表中,與相應的語義::

      (0, 0, { values }) link to a new record that needs to be created with the given values dictionary 
         (1, ID, { values }) update the linked record with id = ID (write *values* on it) 
         (2, ID)    remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) 
    

    實施例: [(0,0,{ 'FIELD_NAME':field_value_record1,...}),(0,0 ,{'field_name':field_value_record2,...})]

  • 對於many2one字段,只需使用必須已存在的目標記錄的ID或False刪除鏈接。

  • 對於基準場,使用一個字符串與模型名,逗號,和目標對象ID(例如:'product.product, 5'
2

(4, ID)表示鏈接到ID = ID的現有記錄,這將添加與現有記錄的關係。

雖然(6, 0, [IDs])表示替換鏈接的ID列表。首先,它將取消鏈接/刪除現有的ID與該記錄,然後鏈接到ID列表中每個ID的現有記錄。

對於刪除現有的ID和鏈路ID,它會刪除兩個對象之間的關係,但不與(6, 0, [IDs])

有關詳細信息刪除目標對象本身,visit here.

1

的選項的完整列表是在documentation for the osv class.

(0,0,{值})鏈接到需要與 創建一個新的記錄給定的數值字典

(1,ID,{值})更新使用id = ID鏈接的記錄(寫上它0值)

(2,ID)移除並刪除使用id = ID鏈接記錄(呼叫取消關聯 上ID,這將刪除完全位於物體,並且鏈接到它作爲 孔)

(3,ID)切割的鏈接使用id = ID鏈接記錄(刪除兩個對象之間的 關係,但不刪除目標 對象本身)

(4,ID)鏈接,與現有的記錄id = ID(增加關係)

(5)u (如使用(3,ID)表示所有鏈接記錄)

(6,0,[ID])替換鏈接ID的列表(如對每個ID使用(5)然後 (4,ID)在ID的列表中)

+0

謝謝我自己發現它在ORM模型寫入方法。 –

相關問題