refactor(admin-model): change MallGoods cate relation from BelongsTo to HasOne
The relationship between MallGoods and MallCate has been updated to reflect a HasOne association rather than a BelongsTo. This change is reflected in the cate() method of the MallGoods model, enhancing the flexibility of the model relationships.
This commit is contained in:
@@ -20,8 +20,6 @@ use think\response\Json;
|
||||
class Goods extends AdminController
|
||||
{
|
||||
|
||||
protected bool $relationSearch = true;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
@@ -36,20 +34,10 @@ class Goods extends AdminController
|
||||
public function index(Request $request): Json|string
|
||||
{
|
||||
if ($request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
if (input('selectFields')) return $this->selectList();
|
||||
list($page, $limit, $where) = $this->buildTableParams();
|
||||
$count = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->count();
|
||||
$list = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select()->toArray();
|
||||
$count = $this->model->where($where)->count();
|
||||
$list = $this->model->with(['cate'])->where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
|
||||
Reference in New Issue
Block a user