ORM 问题 - 未定义 属性

ORM issue - UNDEFINED PROPERTY

我有三个模型具有这些关系:

权限:

public function initialize()
{
    $this->setSchema("ngd_demat");
    $this->setSource("p_permission");
    $this->belongsTo('idAction', Action::class, 'id', ['alias' => 'Action']);
}

操作:

public function initialize()
{
    $this->setSchema("ngd_demat");
    $this->setSource("p_action");
    $this->belongsTo('idResource', Resource::class, 'id', ['alias' => 'Resource']);
    $this->hasMany('id', Permission::class, 'idAction', ['alias' => 'Permission']);
}

资源:

public function initialize()
{
    $this->setSchema("ngd_demat");
    $this->setSource("p_resource");
    $this->hasMany('id',Action::class,'idResource', ['alias' => 'Action']);
}

我想要所有的资源诽谤:

public static function isAllowed($role){
    $resources = [];
    $permission = Permission::find('idRole ='.$role.' AND isAllowed = 1');
    foreach ($permission->action->resource as $resource){
        array_push($resources, $resource->getLibelle());
    }
    return $resources;
}

它 returns 在 apache 错误日志中:

Undefined property: Phalcon\Mvc\Model\Resultset\Simple::$action

Trying to get property 'resource' of non-object

Invalid argument supplied for foreach()

This is the uml class diagram:

我试过使用 Permission::class 或“Security\Permission”或“Permission”以小写和大写形式输入别名,参考模型。我在 loader.php.

中设置了安全命名空间

提前致谢。

我试图通过 Permission::find 找到权限,它是 ResultSet 的一个实例。为了解决这个问题,我使用了 findFirst,它是 Permission.

的一个实例