I have these 2 tables:
CREATE TABLE IF NOT EXISTS `persons` (
`person_id` int(11) NOT NULL AUTO_INCREMENT,
`str_name` varchar(50) NOT NULL,
`str_last_name` varchar(50) NOT NULL,
`dt_birthday` date NOT NULL,
`country_id` int(11) DEFAULT NULL,
PRIMARY KEY (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`str_usr` varchar(35) NOT NULL,
`str_email` varchar(50) NOT NULL,
`str_pwd` varchar(40) NOT NULL,
`person_id` int(11) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `indx_person_id` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `users`
ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `persons` (`person_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
Now, I have these 2 models:
class Person extends \Phalcon\Mvc\Model {
public function getSource() {
return "persons";
}
public function initialize() {
}
public function columnMap() {
return array(
'person_id' => 'id',
'str_name' => 'name',
'str_last_name' => 'lastName',
'dt_birthday' => 'dBirhtday',
'country_id' => 'country'
);
}
}
And
class User extends \Phalcon\Mvc\Model {
public function getSource() {
return "users";
}
public function initialize() {
$this->hasOne("person", "Person", "id");
}
/**
* Mapeamento das colunas do db para aplicação
* @return array
*/
public function columnMap() {
return array(
'user_id' => 'id',
'str_usr' => 'usrName',
'str_email' => 'email',
'str_pwd' => 'password',
'person_id' => 'person'
);
}
public $person; //field to load the person
}
I omitted the getters/setters and fields due the space.
When I try to load the person from a user it is null. Why???