【发布时间】:2014-11-02 19:21:10
【问题描述】:
我有这些表
1 - 产品类别 2 - 产品 3 - 产品型号
和
4 - 引用项目
现在每行报价项都有这些值
id、product_category、product_id、product_model_id、support_product_id、support_prouct_model_id
现在您可以看到报价项目中有产品和产品模型的两个实例。我需要产品名称和产品型号名称才能显示在屏幕上。
当我尝试在控制器中检索数据时,它只从产品和产品模型中带来一个值,而我需要每个产品和产品模型的两个实例。
这是我尝试检索数据的方式。
$quote_items = $this->QuoteItem->find('all', array(
'fields' => array(
'product_category_id',
'product_id',
'product_model_id',
'support_product_id, Product.name',
'support_product_model_id',
'quantity',
'length',
'unit_price',
'total_price',
'ProductCategory.name',
'ProductModel.name'
),
'conditions' => array(
'quote_id' => $this->data['Quote']['quote_id']
),
'contain' => array('Product', 'ProductModel', 'ProductCategory')
));
这就是我所看到的。如您所见,它仅获取第一个产品的产品名称,产品型号相同。
array (size=4)
'QuoteItem' =>
array (size=9)
'product_category_id' => string '3' (length=1)
'product_id' => string '30' (length=2)
'product_model_id' => string '79' (length=2)
'support_product_id' => string '28' (length=2)
'support_product_model_id' => string '73' (length=2)
'quantity' => string '33' (length=2)
'length' => string '1' (length=1)
'unit_price' => string '456' (length=3)
'total_price' => string '15198' (length=5)
'Product' =>
array (size=2)
'name' => string 'p3' (length=2)
'id' => string '30' (length=2)
'ProductCategory' =>
array (size=2)
'name' => string 'Iron' (length=4)
'id' => string '3' (length=1)
'ProductModel' =>
array (size=2)
'name' => string 'm1' (length=2)
'id' => string '79' (length=2)
【问题讨论】:
标签: cakephp cakephp-2.3