cphalcon: [2.1.x] Model alias in getter function not accessible
Example: Defined relation with alias “roles” in Model named “User”.
I defined a getter function named getRoles() where I want to access $this->roles results in error: Undefined property: User::$roles
The relation:
/**
* @HasMany(
* "id",
* "Model\UserRole",
* "userId",
* {
* "alias": "roles"
* }
* )
*/
The function:
public function getRoles()
{
if ($this->getDirtyState() == self::DIRTY_STATE_PERSISTENT) {
$roles = array();
foreach ($this->roles as $role) {
$roles[] = $role->getRole();
}
return $roles;
}
return $this->_roles;
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 47 (47 by maintainers)
Yea then i would agree - i have getters for everything so it could be quite nice to know if i have
__getor__setused anywhere. For now im adding way to disable usage of setters forassignmethod which is used insave/createquite often - i have properties defined but it’s using without need setters anyway. In next versions we could add the same for way to disable__get/__setfor stuff not being relations.