Hi all,
I’m using the latest version of the YiiMongoDBSuite extension (ymds-1.4-pr1).
I’m inserting data into mongoDB with success, there’s no connection issue, but when I query the database with
ModelClass::model()->findAll();
or
ModelClass::model()->find();
I get an array with the right number of elements, the right attributes, but no data:
array(5) (
[0] => User object {
CLASSNAME => (string) User
password => null
login => null
first_name => null
last_name => null
email => null
registerDate => null
useCursor => null
ensureIndexes => (bool) true
_id => null
_embedded => null
_owner => null
}
[1] => User object {
CLASSNAME => (string) User
password => null
login => null
first_name => null
last_name => null
email => null
registerDate => null
useCursor => null
ensureIndexes => (bool) true
_id => null
_embedded => null
_owner => null
}
...
The model is as follow:
class User extends EMongoDocument
{
public $password;
public $login;
public $first_name;
public $last_name;
public $email;
public $registerDate;
/**
* This method have to be defined in every Model
* @return string MongoDB collection name, witch will be used to store documents of this model
*/
public function getCollectionName()
{
return 'users';
}
// We can define rules for fields, just like in normal CModel/CActiveRecord classes
public function rules()
{
return array(
array('login, email, password', 'required'),
array('password', 'validatePwd'),
array('email', 'email'),
);
}
// the same with attribute names
public function attributeNames()
{
return array(
'email' => 'E-Mail Address',
);
}
/*
*/
public function validatePwd($attribute,$params)
{
}
/**
* This method have to be defined in every model, like with normal CActiveRecord
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
I’ve followed the execution in debug mode for a call to User::model()->find();. I’ve found that the extension fetches the data correctly from mongo.
In the EMongoDocument.php class, when it calls the setAttributes function (row 357) the $values array it receives is filled with the right data.
However, when the function then calls
parent::setAttributes($values, $safeOnly);
and moves the execution to the CModel.php class, the attributes aren’t set because the statement
if(isset($attributes[$name])) <-----
$this->$name=$value;
else if($safeOnly)
$this->onUnsafeAttribute($name,$value);
always fails, so the returned array has the right attributes but they’re null.
What can cause this?
Any help?
Thank you,
Riccardo