تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
13297 أدوات العرض

Hi folks, I'm trying to create some db records using xml and can't find any examples on how to create many2many relations. I want to do something like this:

<record model="product.product" id="product_1"> <field name="name">Product 1</field> <field name="product_component_ids" ref="component_id"/> </record>

Thanks! iain

الصورة الرمزية
إهمال
أفضل إجابة

for m2m value in xml use syntax:


<field name="your_field" eval="[(6, 0, [ ref('module_name.external_id_1'), ref('module_name.external_id_2')])]"/>

or 

<field name="your_field" eval="[(0, 0, [ {'field_1':value_1, 'field_2':value_2}] )]"/>

hoep it helps...

الصورة الرمزية
إهمال
أفضل إجابة
tks Bole
eg:
<record model="product.component" id="component_1"> <field name="name">Component 1</field> </record> <record model="product.component" id="component_2"> <field name="name">Component 2</field> </record> <record model="product.product" id="product_1"> <field name="name">Product 1</field> <field name="product_component_ids" eval="[(6, 0, [ ref('component_1'), ref('component_2')])]"/> </record>
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 22
18364
0
يناير 22
2324
3
ديسمبر 23
4677
0
ديسمبر 22
2211
0
يوليو 20
3460