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:
wolfcode
2024-07-01 13:51:58 +08:00
parent 5855a97255
commit df69c2aea4
2 changed files with 16 additions and 18 deletions

View File

@@ -2,8 +2,9 @@
namespace app\admin\model;
use app\common\model\TimeModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
class MallGoods extends TimeModel
{
@@ -12,9 +13,18 @@ class MallGoods extends TimeModel
protected $deleteTime = 'delete_time';
public function cate()
// * +++++++++++++++++++++++++++
// | 以下两种写法适用于 with 关联
// * +++++++++++++++++++++++++
// public function cate(): BelongsTo
// {
// return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
// }
public function cate(): HasOne
{
return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
return $this->hasOne(MallCate::class, 'id', 'cate_id');
}
}