think-orm icon indicating copy to clipboard operation
think-orm copied to clipboard

一对一关联保存无法传入当前模型主键的问题

Open tlerbao opened this issue 4 years ago • 1 comments

Bug

一对一关联保存时,关联表数据保存成功后,当前模型主键并未传过去。

版本

image

我的代码

// 主表定义的关联模型
public function admin()
{
    return $this->hasOne(Users::class,'staff_id','userid');
}
// 控制器测试代码
public function test()
{
    // StaffModel->$pk = userid 主键是userid
    $staff = StaffModel::find('xiaomeng6666');
    // 记录写过去了,但是当前模型主键并没有写入到关联模型的staff_id
    return $staff->admin()->save([
        'username' => '11111',
        'mobile' => '13766554444',
        'password' => 'xxxxx'
    ]);
}

tlerbao avatar Sep 28 '21 03:09 tlerbao

2.0.51 2.0.52依旧存在,还报错

Gooe avatar May 07 '22 15:05 Gooe