easy-swoole / easyswoole

swoole,easyswoole,swoole framework
https://www.easyswoole.com/
Apache License 2.0
4.74k stars 511 forks source link

模型获取器在使用indexBy()方法时无效 #474

Closed SemiThin closed 3 years ago

SemiThin commented 3 years ago

namespace App\Model;

class UsersModel extends BaseModel { protected $autoTimeStamp = true; protected $tableName = 'users';

protected function getAvatarAttr($value)
{
    return $value ? 'http://www.baidu.com/' . $value : '';
}

}

使用 get(); all(); 的时候是有效的 $user = UsersModel::create()->get(1); $user = $user->toArray(); print_r($user);

Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => http://www.baidu.com/custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )

这是使用indexBy 获取时候时 avatar 字段并没有经过处理 $user = UsersModel::create()->indexBy('id'); print_r($user);

Array ( [1] => Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )

)

Player626 commented 3 years ago

这个indexBy不走gettet.你关闭掉吧.群里应该是回答你了.