ORM问题-未定义的属性

问题描述

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

权限:

public List<List<string>> GetListFromExcel(string FileName)
{
    try
    {
        List<List<string>> sListOfRecords = new List<List<string>>();
        IExcelDataReader reader = null;
        using (var stream = System.IO.File.OpenRead(FileName))
        {
            string sExtension = Path.GetExtension(FileName);
            if (sExtension == ".xls")
            {
                reader = ExcelReaderFactory.CreateBinaryReader(stream);
            }
            else
            {
                reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            }
            reader.IsFirstRowAsColumnNames = true;
            DataSet result = reader.AsDataSet();
            reader.Close();
            DataTable data = result.Tables[0];
            var excelColdata = new List<string>();
            foreach (DataRow row in data.Rows)
            {
                var excelRowdata = new List<string>();
                foreach (var item in row.ItemArray)
                {
                    excelRowdata.Add(item.ToString());
                }
                if (excelRowdata.Where(m => !string.IsNullOrWhiteSpace(m)).Count() > 0)
                {
                    sListOfRecords.Add(excelRowdata);
                }
            }
        }

        return sListOfRecords.Distinct().ToList();
    }
    catch (Exception ex)
    {
        ServiceUtil.LogError(ex);
        log.Error("Error",ex);
        throw ex;
    }

}

操作:

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,['alias' => 'Resource']);
    $this->hasMany('id',Permission::class,'idAction',['alias' => 'Permission']);
}

我想要所有的资源诽谤:​​

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

它返回apache错误日志:

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

This is the uml class diagram:

我试图用Permission :: class或“ Security \ Permission”或“ Permission”将别名以小写和大写形式引用。我在loader.php中设置了安全名称空间。

谢谢。

解决方法

我试图使用Permission :: find来查找许可,该许可是ResultSet的一个实例。为了解决这个问题,我使用了 findFirst ,它是Permission的一个实例。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...