easy-swoole / easyswoole

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

orm 使用hidden无效 #449

Closed mirgong closed 3 years ago

mirgong commented 3 years ago

$list = DbManager::getInstance()->invoke(function ($client)use ($where,$page,$page_num){ $model = ClientWitnessModel::invoke($client); $fields = "c.*"; $res = $model->alias("c") ->field($fields) ->join("ymt_client_witness_appointment_date as cd",'c.client_witness_id = cd.client_witness_id','LEFT') ->where($where) ->page($page,$page_num) ->group("c.client_witness_id") ->hidden(['c.img','c.img_list']); ->withTotalCount() ->all() ; $total = $model->lastQueryResult()->getTotalCount(); return ['total' => $total, 'list' => $res]; });

sql :SELECT SQL_CALC_FOUND_ROWS c.* FROM ymt_client_witness AS c LEFT JOIN ymt_client_witness_appointment_date as cd on c.client_witness_id = cd.client_witness_id WHERE c.company_id = 3473 AND c.is_open_partner = 1 GROUP BY c.client_witness_id LIMIT 0, 10

结果还是显示了img,img_list,字段并未隐藏,orm 版本:easyswoole/orm 1.4.31 php stander lib

Player626 commented 3 years ago

https://www.easyswoole.com/Components/Orm/toArray.html https://github.com/easy-swoole/orm/blob/master/tests/CollectionTest.php get时无需设置returnCollection即可调用hidden,visible, append. all需要设置returnCollection才可以调用,或者foreach -> toArray(false,false). 两者前提都需要toArray(false,false),你只要能调用到toArray那么就可以使用.但这样的数据必须toArray(false,false)才会显示.