Hi all,
I'm implementing Phalcon ORM and have an issue with relations between models. To be accurate, I had a test code working with staticly included classes. Then I've started using namespaces, added an autoloader and it doesn't work anymore.
My test code:
//includes model class and return a new UsersModel
$oUser = $this->_getModel('users');
$aoUsers = $oUser::find(array('order' => 'id ASC'));
foreach($aoUsers as $oUser)
{
dump($oUser->id);
dump($oUser->profiles);
}
As expected the resultset was containing the user & profile data. Now I've changed the relation declarations with Namespaces, the resultset only contains the user data. My Models:
namespace Phalcon\Mvc\Model;
class Users extends \Phalcon\Mvc\Model\ModelBase
{
namespace Phalcon\Mvc\Model;
public function initialize()
{
$this->useDynamicUpdate(true);
$this->hasOne("id", "\Phalcon\Mvc\Model\Profiles", "id");
}
public function metaData()
{
//generating my own meta here.
}
}
Second model:
namespace Phalcon\Mvc\Model;
class Profiles extends \Phalcon\Mvc\Model\ModelBase
{
namespace Phalcon\Mvc\Model;
public function initialize()
{
$this->useDynamicUpdate(true);
$this->belongsTo("id", "\Phalcon\Mvc\Model\Users", "id");
}
public function metaData()
{
//generating my own meta here.
}
}
If I dump the ModelManager, I see it's set up properly:
$oManager = $oUser->getModelsManager();
dump($oManager);
dump('relations ?');
$oRelation = $oManager->getRelations("profiles");
dump($oRelation);
//Outputs:
Object(Phalcon\Mvc\Model\Manager) =>
array(24) {
["*_dependencyInjector"]=>
string(24) " *** Phalcon object *** "
["*_eventsManager"]=>
NULL
["*_customEventsManager"]=>
NULL
["*_readConnectionServices"]=>
NULL
["*_writeConnectionServices"]=>
NULL
["*_aliases"]=>
array(1) {
["phalcon\mvc\model\users$\phalcon\mvc\model\profiles"]=>
array(8) {
["*_type"]=>
int(2)
["*_referencedModel"]=>
string(27) "\Phalcon\Mvc\Model\Profiles"
["*_fields"]=>
string(2) "id"
["*_referencedFields"]=>
string(2) "id"
["*_intermediateModel"]=>
NULL
["*_intermediateFields"]=>
NULL
["*_intermediateReferencedFields"]=>
NULL
["*_options"]=>
NULL
}
}
["*_hasMany"]=>
array(1) {
["phalcon\mvc\model\users$\phalcon\mvc\model\profiles"]=>
array(1) {
[0]=>
[...]
//And relations:
array (
0 =>
Phalcon\Mvc\Model\Relation::__set_state(array(
'_type' => 2,
'_referencedModel' => '\\Phalcon\\Mvc\\Model\\Profiles',
'_fields' => 'id',
'_referencedFields' => 'id',
'_intermediateModel' => NULL,
'_intermediateFields' => NULL,
'_intermediateReferencedFields' => NULL,
'_options' => NULL,
)),
)
What is wrong ?