-
Notifications
You must be signed in to change notification settings - Fork 184
Open
Description
打印测试代码
Route::get('test', function () {
$data = \app\entity\Orders::find(84);
dump($data);
});
报错信息
Cannot assign null to property app\entity\Orders::$mstatus of type string
<?php
// +----------------------------------------------------------------------
// | 商户模型
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
class Merchants extends Model
{
}
<?php
// +----------------------------------------------------------------------
// | 订单模型
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
use think\model\relation\BelongsTo;
class Orders extends Model
{
/**
* 关联商户
*/
public function merchant(): BelongsTo
{
return $this->belongsTo(Merchants::class, 'merchant_id', 'id');
}
}
<?php
// +----------------------------------------------------------------------
// | 商户视图模型
// +----------------------------------------------------------------------
namespace app\entity;
use think\model\View;
class Merchants extends View
{
public string $id;
public string $status;
}
<?php
// +----------------------------------------------------------------------
// | 订单视图模型
// +----------------------------------------------------------------------
namespace app\entity;
use think\model\View;
class Orders extends View
{
public string $id;
public string $merchant_id;
public string $amount;
public string $mstatus;
public function getOptions():array
{
return [
//'autoMapping' => ['merchant']
'viewMapping' => ['mstatus' => 'merchant->status']
];
}
}
Metadata
Metadata
Assignees
Labels
No labels