I want to fetch records from table for names starting with a, b or c but with status=pending in cakephp 3.0. I am trying below query. Please check what is wrong with it as it is also fetching results starting with name 's':
$this->loadModel('DbArtists');
/*** fetching records alphabetically ***/
$artists_q = $this->DbArtists->find()->where(['album_status' => 'pending'])->orWhere(['name ' => 'A%', 'name ' => 'B%', 'name' => 'C%']);
$artist = $artists_q->all();
echo "<pre>";print_r($artist);die;
Do like below:-
$artists_q = $this->DbArtists->find()->where([
'album_status' => 'pending',
'OR' => [['name LIKE' => 'A%'],['name LIKE' => 'B%'],['name LIKE' => 'C%']],
]);
Or you can chek once this too:-
$query = $articles->find()->where(['album_status' => 'pending'])
->orWhere(['name LIKE' => 'A%'])
->orWhere(['name LIKE' => 'B%'])
->orWhere(['name LIKE' => 'C%']);
Reference:- https://book.cakephp.org/3.0/en/orm/query-builder.html