a Post has_many tags (id, title, text)
a Tag belongs_to many posts (id, name)
ends up in a many_many-relation PostTag (postId, tagId)
how to get a paginated list of tags?
Any idea?
a Post has_many tags (id, title, text)
a Tag belongs_to many posts (id, name)
ends up in a many_many-relation PostTag (postId, tagId)
how to get a paginated list of tags?
Any idea?
If you only have one post, then you may paginate the tags using: $tags=$post->tags(array(‘limit’=>10,‘offset’=>0));
Here’s how I did sort & pagination on many_many:
$pages=new CPagination($model->modelsCount); // modelsCount is a STAT relation
$pages->pageSize=self::PAGE_SIZE;
$sort=new CSort('Model');
$order = array();
foreach ($sort->getDirections() as $field => $direction)
{
$field = '??.'.$field;
if ($direction)
$order[] = $field.' ASC';
else
$order[] = $field.' DESC';
}
$models = $model->models(array('order'=>implode(',', $order), 'limit'=>$pages->getPageSize(), 'offset'=>$pages->getPageSize()*$pages->getCurrentPage()));