2
我有2多对多关系表;帖子和分类。一篇文章可以有很多类别。我的问题是如何显示其分类的帖子列表?Codeigniter Datamapper多对多列表
就像是:
我交1(CAT1,CAT2,CAT3)
我交2(CAT2,CAT3)
我交3(CAT1)
我已经试过这些方法;
// Create post object
$p = new Post();
// Get 30 posts
$p->get(30);
// Loop through all posts
foreach ($p as $post)
{
// Get the current user's group
$post->category->get();
foreach($post->category as $category) {
// ...
}
}
不喜欢这一点,因为如果我得到30个职位,然后在每一个岗位循环再次进行查询,并一次又一次地找到类别。
,并试图此:
$p = new Post();
$p->include_related('category', array('id', 'name'), TRUE, TRUE)->get(30);
foreach($p as $post) {
// ...
foreach($post->category as $category) {
// ...
}
}
这是更接近,但这个问题是我设置的限制get(30)
因此,如果平均每个职位有我的2个大类显示15个后+ 15个类别。
多对多上市的真实方法是什么?