Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND Post.id IN () #1370

Open
only4r opened this issue Sep 23, 2023 · 1 comment
Open

AND Post.id IN () #1370

only4r opened this issue Sep 23, 2023 · 1 comment

Comments

@only4r
Copy link

only4r commented Sep 23, 2023

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
Copy link
Member

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()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants