I'm using Phalcon PHP with multi modules structure and I want to use a magic getter on my object but the getter is null when I'm trying to do a var_dump.
Snippet Model Users
namespace Apps\Common\Models;
use Phalcon\Mvc\Model;
class Users extends Model{
public $id;
public $city_id;
public $name;
...
public function initialize(){
$this->belongsTo("city_id", "City", "id");
}
}
Snippet Model City
namespace Apps\Common\Models;
use Phalcon\Mvc\Model;
class City extends Model{
public $id;
public $name;
...
public function initialize(){
$this->hasMany("id", "Users", "city_id");
}
}
Magic getter utilization
public function addAction() {
$user = Users::findFirst(array(
"id = :id:",
"bind" => array('id' => 2)
));
city = $user->getCity(); // This is null
echo city->name;
}
Do you know why this magic getter $user->getCity();
doesn't work ?
Thanks.