UnionOfRAD / lithium

li₃ is the fast, flexible and most RAD development framework for PHP
http://li3.me
BSD 3-Clause "New" or "Revised" License
1.22k stars 237 forks source link

AND Post.id IN () #1370

Open only4r opened 1 year ago

only4r commented 1 year ago

Hey,

I think my Lithium version: v0.10.0

My problem:

If empty the keywords input, everything is okay. If send keywords, error:

lithium\data\model\QueryException (code 1064)
SELECT * FROM `posts` AS `Post` LEFT JOIN `posts_attachments` AS `PostsAttachment` ON `Post`.`id` = `PostsAttachment`.`post_id` WHERE `keywords` like '%hello%' AND Post.id IN () ORDER BY Post.id DESC;: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY Post.id DESC' at line 1

Not need this: AND Post.id IN () ... but why here?

Controller:

$conditions = array();
$query = isset($this->request->query) ? $this->request->query : array();
if(isset($query['keywords']) && $query['keywords'] != '') {
  $conditions[] = array( 'title'=>array('like' => '%'.$query['keywords'].'%') );
}
$limit = 25;
$page = $this->request->page ?: 1;
$total = Post::count();
$total_current = Post::count(array('conditions' => $conditions));
$accounts = Post::all(array(
  'conditions' => $conditions,
  'with' => array('PostsAttachment'),
  'order' => 'Post.id DESC',
  'page' => $page,
  'limit' => $limit
));
$posts = $posts->to('array');
return compact('posts');

View:

$query = (count($this->_request->query) > 0)? $this->_request->query : false;
echo $this->form->create(null, array(
    'id' => 'filter',
    'method' => 'get',
    'url' => '/post/index'
));
echo $this->form->field('keywords', array(
    'label' => false,
    'placeholder' => 'Search',
    'value' => isset($query['keywords']) ? $query['keywords'] : ''
));
echo $this->form->submit('Search', array(
    'type' => 'submit',
    'class' => 'button'
));
echo $this->form->end();
echo '<p>' . $this-> Paginator-> paginate() . '</p>';

What is the problem?

nateabele commented 1 year ago

That's a strange error, but I don't know if we'll be able to help you, since 0.10.0 has not been supported for a very long time.

Can you post the var_export() dump of the query you're passing to Post::all()?