top-think/think

bindAttr

Opened this issue · 0 comments

bindAttr支持指定属性别名 方法有个小bUG

vendor/topthink/think-orm/src/model/concern/RelationShip.php 中bindAttr 方法
官方文档地址
https://www.kancloud.cn/manual/thinkphp6_0/1037600
同样支持指定属性别名
$user = User::find(1)->bindAttr('profile',[
'email',
'truename' => 'nickname',
]);
// 输出Profile关联模型的email属性
echo $user->email;
echo $user->truename;
在某些特殊情况下 会绑定失败
$relation = $this->getRelation($relation); (351行) 返回为模型数组
当$attr 为 $relation 中存在的特殊字符时 例如 name 会获取 $relation 中name的值

$this->set($key, $relation ? $relation->$attr : null);(361)
而不是从$relation[data] 取值

建议将$relation 转换成数组 判断值是否存在

PHP 版本7.34NTS apache2.4.39 TP 6.0