【问题标题】:Laravel dissociate for hasOne relationLaravel 分离 hasOne 关系
【发布时间】:2017-04-21 19:02:48
【问题描述】:

对于belongsTo 关系,我可以使用dissociate,但hasOne 的等价物是什么?

例如。 Phone 属于User

$phone->user()->dissociate(); // success
$user->phone()->dissociate(); // fail

【问题讨论】:

    标签: laravel orm eloquent


    【解决方案1】:

    似乎没有反向等价物。

    自从

    $user->phone()
    

    返回一个Illuminate\Database\Eloquent\Relations\HasOne 对象,让我们看看that file - 没有dissociate() 等效方法。但是HasOne 扩展了HasOneOrMany,所以为了安全起见,让我们使用look on that too。依然没有。

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 2018-05-29
      • 2016-03-17
      • 1970-01-01
      • 2020-04-09
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      相关资源
      最近更新 更多