【问题标题】:How to join model in xmlrpc using ripcord?如何使用 ripcord 在 xmlrpc 中加入模型?
【发布时间】:2017-08-25 08:14:43
【问题描述】:

我有 2 个模型:product.templateproduct.brand。 我想显示来自 product.template 及其品牌的详细数据,我可以从 product.brand 的模型中获得该品牌。在模型 product.brand 中包含 product_id,它与 product.template 中的 id 有关系。这是我当前的代码。此代码仅显示来自 product.template 的数据。

<?php    
$products = $ripcord->execute_kw('myDB', 1, 'myPassword',
                        'product.template', 'search_read',
                        array(
                            array(
                            array('name', 'ilike', 'pixma'),
                            array('type', 'ilike', 'product'),
                        ['fields'=>array('name', 'description'), 'limit'=>5]
                     ))); 
?>

如何将 product.template 模型与 product.brand 加入,以便获得数据的产品品牌。谢谢。

【问题讨论】:

    标签: php openerp ripcord


    【解决方案1】:

    您需要在fields 中包含对品牌的引用。

    <?php
    
    $db = 'myDB';
    $uid = 1;
    $password = 'myPassword';
    
    # You will need to include a reference to the Many2one field
    # that exists on your product.template record. I'm assuming it's
    # called something like "brand" or "brand_id"
    $fields = array('name', 'description', 'brand');
    
    
    $products = $ripcord->execute_kw($db, $uid, $password,
        'product.template', 'search_read', array(array(
            array('name', 'ilike', 'pixma'),
            array('type', 'ilike', 'product'),
            ['fields'=> $fields, 'limit'=>5]))); 
    

    【讨论】:

    • 我明白了。但假设在product.template 包含字段:idnametypebranddescription。在product.brand 中包含字段:idbrand_namecategory_brandpriceproduct.template 中的 brandproduct.brand 中的 id 相关。我想展示的是来自product.templatenamedescription 和来自product.brandcategory_brandprice。如果我只是像你说的那样输入brand 字段,它只是显示id 的品牌。我怎样才能同时显示category_brandprice?谢谢你:)
    • 据我所知,您必须提出多个请求。因此,您将只从 product.brand 中提取 id,并针对该模型的字段发出另一个 search_read 请求。可以编写自己的辅助方法来使用点符号并自动拉取关系,但 Odoo 的 api 不直接提供该功能。
    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 2015-06-16
    相关资源
    最近更新 更多