2017-08-25 3 views
0

私はproduct.templateproduct.brandの2モデルです。 product.brandのモデルから得ることができるブランドであるproduct.templateとそのブランドの詳細データを表示したい。モデルproduct.brにproduct.templateのidと関係のあるproduct_idが含まれています。ここに私の現在のコードがあります。このコードはproduct.templateからのデータのみを表示します。ripcordを使ってxmlrpcでモデルに参加するには?

私はproduct.templateモデルをproduct.brandに参加させて、データの商品ブランドを取得する方法を教えてください。ありがとうございました。

答えて

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]))); 
+1

私はそれを得ました。 'product.template'には' id'、 'name'、' type'、 'brand'、' description'の各フィールドがあります。 'product.brand'には' id'、 'brand_name'、' category_brand'、 'price'の各フィールドがあります。 'product.template'の' brand'は 'product.brand'の' id'と関連しています。私は 'product.template'と' category_brand'と 'product.brand'から' price'から 'name'と' description'を表示したいと思います。 あなたが言ったように 'brand'フィールドを置くだけで、idのブランドを表示するだけです。 'category_brand'と' price'もどのように表示できますか? ありがとうございました:) – adn

+0

私の知る限り、複数のリクエストをしなければなりません。だから、あなたはproduct.brandからidだけを取り出し、そのモデルに対して別の 'search_read'要求をそのフィールドに対して行います。ドット表記を使用して自動的にリレーションを引き出す独自のヘルパーメソッドを書くことは可能ですが、OdooのAPIは機能を直接提供していません。 – holdenrehg

+0

あなたの情報をありがとうございました – adn

関連する問題