作者:手机用户2602880641 | 来源:互联网 | 2023-05-19 05:08
ImusingKohana3.3ORM.Ihavethefollowingmodelsdefined:我正在使用Kohana3.3ORM。我定义了以下模型:class
I'm using Kohana 3.3 ORM. I have the following models defined:
我正在使用Kohana 3.3 ORM。我定义了以下模型:
class Model_Post extends ORM {
protected $_primary_key = 'ObjID';
protected $_has_many = array(
'categories' => array(
'model' => 'Category',
'through' => 'posts2categories',
'foreign_key' => 'post_id',
),
);
}
and
和
class Model_Category extends ORM {
protected $_has_many = array(
'posts' => array(
'model' => 'Post',
'through' => 'posts2categories',
'foreign_key' => 'category_id',
),
);
}
now, fetching all posts belonging to ONE category is very easy:
现在,获取属于ONE类别的所有帖子非常简单:
$posts = $categoriesQuery->where('category_id','=',1)->find()->posts->find_all();
I want to know how to fetch all posts belonging to category 1 OR 2. I tried many things, and non of them worked. How can I make it work? I there a way of doing it using the ORM module and not with a direct SQL query?
我想知道如何获取属于类别1或2的所有帖子。我尝试了很多东西,并且没有使用它们。我怎样才能使它工作?我有一种方法可以使用ORM模块而不是直接的SQL查询吗?
2 个解决方案