【发布时间】:2014-04-25 12:54:38
【问题描述】:
我有一个表 products 有几个关联 示例:
我想在查看所有带有条件的产品的数据时使用
这是产品型号:
<?php
class Product extends Model {
public $hasAndBelongsToMany = array('Label','PircingScale');
public $hasMany = array('LabelR','PircingScaleR');
}
还有标签模型:
<?php
class Label extends Model {
public $hasAndBelongsToMany = array('Product');
}
以及关系模型:
<?php
class LabelR extends Model {
public $useTable = 'labels_products';
public $belongsTo = array('Product','Label');
}
与 pircing_scale 模型相同
现在我在索引控制器上找到了:
<?php
class IndexController extends AppController {
public $uses = array('Product','Label','PircingScale');
public function index() {
$this->set('lastNewProduct', $this->Product->LabelR->find('all', array(
'conditions' => array('Label.id' => 1),
'limit' => 3,
)));
}
}
在我看来,我想在 pircing_scale 中显示所有产品的信息
【问题讨论】:
-
请告诉我们你到目前为止做了什么
-
这个简短的问题有很多答案。请说明您的问题。
-
对不起,我已经编辑了我的答案
-
不,我想按标签查找所有产品,并使用此结果显示有关该产品的所有信息(例如,定价比例)