【发布时间】:2013-01-07 11:55:05
【问题描述】:
我正在为我的项目使用 CakePHP... 为了加快我的代码,我只想获得一些与我的实际对象相关的模型:
$result = $this->Category->find(
'first',
array(
'conditions' => array(
'Category.folder' => $path[0]
),
'contain' => array('Rubric',
'conditions' => array('Rubric.category_id' => 'Category.id'),
'contain' => array('Subrubric',
'conditions' => array('Subrubric.rubric_id' => 'Rubric.id')
)
)
)
);
path[0] 是来自 url 的参数...
找到了类别和评分准则,但没有找到子评分准则。还有一些与我的对象相关的条目,但我希望它们在我的 rubric-view 中而不是在 category-view 中。
模型关系:
类别:
public $hasMany = array(
'Rubric' => array(
'className' => 'Rubric',
'foreignKey' => 'category_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => 'title',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
评分标准:
public $hasMany = array(
'Entrieslocation' => array(
'className' => 'Entrieslocation',
'foreignKey' => 'rubric_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Subrubric' => array(
'className' => 'Subrubric',
'foreignKey' => 'rubric_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
这里我不想要入口位置...
【问题讨论】:
标签: php cakephp model database-relations