easy-swoole / orm

31 stars 27 forks source link

orm 数据表字段和查询模型属性冲突时会报错 #153

Closed bodyTop closed 3 years ago

bodyTop commented 4 years ago

easyswoole框架版本号 3.3.6、orm组件版本号 1.4.5

问题描述和截图 [Question]

  1. 表查询结果后转数组 $taskInfo->toArray() 2.[Too few arguments to function EasySwoole\ORM\AbstractModel::hidden(), 0 passed in 遇到此报错 3.public function getAttr($attrName) {

    $method = 'get' . str_replace( ' ', '', ucwords( str_replace( ['-', '_'], ' ', $attrName ) ) ) . 'Attr';
    if (method_exists($this, $method)) {
        return call_user_func([$this,$method],$this->data[$attrName] ?? null, $this->data);
    }
    // 判断是否有关联查询
    $notWhile = ['count', 'where', 'order', 'alias', 'join', 'with', 'max', 'min', 'avg','sum', 'field', 'get', 'all', 'delete', 'result'];
    if (method_exists($this, $attrName) && !in_array($attrName, $notWhile) ) {
        我的数据表中存在一个hidden字段, 这里会自动去调用对象中hidden的属性
        return $this->$attrName();
    }
    // 是否是附加字段
    if (isset($this->_joinData[$attrName])){
        return $this->_joinData[$attrName];
    }
    return $this->data[$attrName] ?? null;

    }

  2. /* @var array toArray时候需要隐藏的字段 / private $hidden = [];

排查情况和最小复现脚本 [Tests and Recurrence]

xuanyanwow commented 4 years ago

版本过低,升级后重试