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

How can I find a record in database using its External Id?

Let's say I have the following record in my data file:

<record model="product.product" id="product_to_find"> ... </record> 

How can I retrieve it in code-behind?

アバター
破棄
最善の回答

You can now do self.env.ref('external.identifier') 

アバター
破棄
最善の回答

You retrieve it with a code like:

res_model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'module','product_to_find')
product = self.pool.get(res_model).browse(cr, uid, res_id)

or using the new api

res_model, res_id = self.env['ir.model.data'].get_object_reference('module','product_to_find')
product = self.env[res_model].browse(res_id) 


アバター
破棄

To complete this answeer... get_object(...) return immediately the record in new API. The same in old API is : xmlid_to_object(...)

最善の回答

Try to search it the same way searching the view id of a certain view 



アバター
破棄
関連投稿 返信 ビュー 活動
2
1月 17
6264
2
7月 17
15666
2
11月 15
4426
0
3月 25
1420
0
1月 25
3502