Reputation: 28783
I have the following find code:
if($this->User->find('first', array(
'conditions' => array(
'User.username' => $this->data['User']['username'],
'User.email' => $this->data['User']['username'])
)))
The idea is that it will find if a user exists with an email or username that matches what was sent in the username input field.
The problem is that in fact it will try and match BOTH rather than one or the other which is what I really want. How do I do this though?
I tried with the following but still no success:
if($this->User->find('first', array(
'conditions' => array('OR' => array(
array('User.username' => $this->data['User']['username']),
array('User.email' => $this->data['User']['username'])))))
Thanks
Upvotes: 0
Views: 647
Reputation: 50009
You were close, it should go like this
$opts = array(
'conditions' => array(
'or' => array(
'User.username' => $this->data['User']['username'],
'User.email' => $this->data['User']['username']
)
)
)
$this->User->find('first', $opts)
Upvotes: 4