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)

Most upvoted comments

Yea then i would agree - i have getters for everything so it could be quite nice to know if i have __get or __set used anywhere. For now im adding way to disable usage of setters for assign method which is used in save/create quite 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/__set for stuff not being relations.