TP5 模型用field() 方法查詢 有一個字段不顯示
商品表 模型
/**
* 定義商品和商品評論表之間得關系
*
* @return \think\model\relation\HasMany
*/
public function goodsComment() {
return $this->hasMany('MallComment', 'goods_id', 'id')->field('user_id,comment,comment_type,create_time');
}
控制器使用
$goodsInfo = Goods::goodsInfo($data['goods_id']);
$goodsInfo->goodsComment()->order('create_time desc')->limit(0, 1)->select();
返回結果
"goodsComment": [
{
"user_id": 33,
"comment": "你好",
"comment_type": 2,
"user": {
"nickname": "XX",
"photo": "9f1cd8fd29d4b17ccd93b333ff558118.png"
}
},
{
"user_id": 33,
"comment": "哈哈",
"comment_type": 1,
"user": {
"nickname": "XX",
"photo": "9f1cd8fd29d4b17ccd93b333ff558118.png"
}
}
]
返回結果中并沒有create_time字段 并且 limit 和 order方法都失效了 數據庫里是存在值得
請大神指教下
添加回答
舉報
0/150
提交
取消