Here is code:
AppController
'authenticate' => [
'Form' => [
'finder' => 'emailOrNameAuth',
'fields' => ['username' => 'name', 'password' => 'password']
]
],
Users table:
#options 1:
public function findEmailOrNameAuth(\Cake\ORM\Query $query, array $options)
{
$query
->where([
'OR' => [
['email' => $options['username']]
],
'activated' => 1,
]);
return $query;
}
// FROM
users Users
WHERE
(
Users.name = 'xxxxxx'
AND email = 'xxxxxt'
AND activated = 1
)
Old deprecated options return valid query:
public function findEmailOrNameAuth(\Cake\ORM\Query $query, array $options)
{
$query
->orWhere(['email' => $options['username']])
->andWhere(['activated' => 1]);
return $query;
}
// FROM users Users WHERE ((Users.name = :c0 OR email = :c1) AND activated = :c2)
The function
Cake\Database\Query::orWhere()
has been deprecated: 3.5.0 This method creates hard to predict SQL based on the current query state. UseQuery::where()
instead as it has more predicatable and easier to understand behavior.
How to fix?