ormphalconrelationphalcon-orm

ORM issue - UNDEFINED PROPERTY


I have three models with these relations :

Permission :

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

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']);
}

Resource :

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

I want all the resource libelle :

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;
}

It returns in apache error log :

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:

I've tried to put alias in lowercase and uppercase, reference model with Permission::class or "Security\Permission" or "Permission". I have Security namespace set in my loader.php.

Thanks in advance.


Solution

  • I tried to find permission with Permission::find which is an instance of ResultSet. To fix this i used findFirst which is an instance of Permission.