I've discovered a strange behavior on the query builder, and I don't know if there is an issue or am I doing something wrong.
Essentially I have this query:
PHP Code:
$builder = $this->post
->select('blog_posts.*, users.username as author')
->join('users', 'blog_posts.author_id = users.id', 'left')
->where('type', $type)
->groupStart()
->like('title', $search)
->orLike('content', $search)
->groupEnd()
->orderBy($order, $sort);
as you can see I have applied a "where" with a group condition that contains the "like" operator.
When I execute the query using:
PHP Code:
$posts = $builder->limit($rows, $page)->paginate(1);
I get:
PHP Code:
SELECT `blog_posts`.*, `users`.`username` as `author`
FROM `blog_posts`
LEFT JOIN `users` ON `blog_posts`.`author_id` = `users`.`id`
WHERE `type` = 'post'
AND (
`title` LIKE '%%' ESCAPE '!'
OR `content` LIKE '%%' ESCAPE '!'
)
ORDER BY `title` ASC
LIMIT 1
Until here no problem, but I'm trying to get the next set of data using:
PHP Code:
$hasNext = !empty($builder->limit($rows, $page + 1)->paginate(1));
and the query is completely wrong and different (I'm using the same $builder):
PHP Code:
SELECT *
FROM `blog_posts`
LIMIT 1, 1
if I comment the previous line:
PHP Code:
$posts = $builder->limit($rows, $page)->paginate(1);
the query is correct, why happen this? Should I create a new builder each time?