gpt4 book ai didi

php - 蛋糕 php 包含在包含

转载 作者:搜寻专家 更新时间:2023-10-31 20:44:54 27 4
gpt4 key购买 nike

我正在为我的项目使用 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 的参数...

已找到类别和评分标准,但未找到子评分标准。也有与我的对象相关的条目,但我希望它们在我的标题 View 中而不是在类别 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' => ''
)
);

这里我不需要入口位置...

最佳答案

看这个:Containing deeper associations

你不应该在更深层次的关系中使用节点“包含”。您的代码应如下所示。

 $result = $this->Category->find(
'first',
array(
'conditions' => array(
'Category.folder' => $path[0]
),
'contain' => array('Rubric',
'conditions' => array('Rubric.category_id' => 'Category.id'),
'Subrubric' => array(
'conditions' => array('Subrubric.rubric_id' => 'Rubric.id')
)
)
)
);

关于php - 蛋糕 php 包含在包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14489274/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com