【发布时间】:2012-01-09 01:45:38
【问题描述】:
这是我的情况,我有一个可以属于多个类别的 Post 模型。这我想出了怎么做:
class Post extends AppModel
{
var $hasAndBelongsToMany = array('Category');
}
以及类别模型:
class Category extends AppModel
{
var $hasAndBelongsToMany = array ('Post');
}
现在,这一切都很好。但我就是不知道如何搜索属于某个类别的帖子,例如要使用的 id 为 1 的“新闻”:
class CategoriesController extends AppController {
function view ($id = 0) {
// doesnt work
$this->Category->Video->find ('all', array('conditions' => array('category_id' => $id));
}
}
我一直试图在 Google 和 CookBook 上找到答案,但还没有找到任何答案。有谁知道如何做到这一点?
谢谢。
【问题讨论】:
标签: cakephp has-and-belongs-to-many