$posts = Model_Post::query()->related('tags');
strlen($q) > 2 && $posts = $posts->where('name', 'LIKE', '%'.$q.'%');
isset($tag) && $posts = $posts->where('tags.id', $tag);
$posts = $posts->get();
public static function search($q, $tag)
{
$posts = Model_Post::query()->related('tags');
strlen($q) > 2 && $posts = $posts->where('name', 'LIKE', '%'.$q.'%');
isset($tag) && $posts = $posts->where('tags.id', $tag);
$posts = $posts->get();
$ids = array();
foreach($posts as $post)
$ids[] = $post->id;
return Model_Post::query()->related('tags')
->where('id', 'IN', $ids);
}
$posts = Model_Post::search(Input::get('q'), Input::get('tag'))
->limit(10)
->offset(Input::get('skip'))
->get();
public static function search($q, $tag)This should work fine too.
{
$posts = static::query()->related('tags');
strlen($q) > 2 && $posts = $posts->where('name', 'LIKE', '%'.$q.'%');
isset($tag) && $posts = $posts->where('tags.id', $tag);
return $posts;
}
$posts = Model_Post::search(Input::get('q'), Input::get('tag'))otherwise you may not get the desired result, as ORM will retrieve complete posts->tags sets when you use limit().
->rows_limit(10)
->rows_offset(Input::get('skip'))
->get();
It looks like you're new here. If you want to get involved, click one of these buttons!