I've been using Cake for quite some time, and I noticed something strange for the first time today while writing a simple search Behavior. I'm not doing anything complex, just using $Model->find()
s on different Models after initializing $Model
as ClassRegistry::init('Model')
. Everything works great, except I have a database field named login
in one of the tables. The value of this field returns as *****
for any rows that I perform a search on! This does not happen while using find()
s in the Controller or Model, just in the Behavior. Below is my code:
...
...
$Model = ClassRegistry::init('User');
$fields = array('User.login', 'User.name', 'RelatedModel.field1', 'RelatedModel.field2');
$contain = array('RelatedModel');
if($searchBy === "name") {
//some code and set $conditions
} else {
//else some other code and set $conditions
}
$Model->Behaviors->load('Containable');
$results = $Model->find('all', array('conditions' => $conditions, 'fields' => $fields, 'contain' => $contain));
return $results;
And this is what debug()
is showing:
array(
(int) 0 => array(
'User' => array(
'login' => '*****',
'name' => 'John Doe',
'passwd' => 'a291a5c901cf51b75b6a50135ed5a04bc2e90c54',
),
'RelatedModel' => array(
'field1' => 'XXXXXXXX',
'field2' => '7002'
)
)
)
The actual result should be 'login' => 'nsps_2013'
, as it most definitely is when I use find()
in the UserController
and UserModel
.