该如何处理?我尝试过:
return $this->hasMany(ResolutionLog::class, 'ant_id', 'id')->with('resolutionStatus');
并显示错误:
调用模型[App \ Models \ ResolutionLog]上未定义的关系[resolutionLog]。
或者在修补程序中,我在获取resolutionLog
集合并尝试访问resolutionStatus
关系时遇到此错误:
带有消息“ App / Models / ResolutionLog :: resolutionStatus必须返回关系实例”的LogicException。
这是resolutionStatus
模型上的ResolutionLog
关系:
ResolutionLog.php
public function resolutionStatus()
{
$this->hasOne(ResolutionStatus::class, 'id', 'resolution_status_id');
}
以及resolutionLog
模型上的ResolutionStatus
关系:
ResolutionStatus.php
public function resolutionLog()
{
return $this->hasMany(ResolutionLog::class, 'resolution_status_id', 'id');
}
ResolutionLog
和一个ResolutionStatus
之间应该是一个多对多的关系。一个ResolutionStatus
可以有多个ResolutionLog
。
答案 0 :(得分:4)
您应该像这样返回关系:
public function resolutionStatus()
{
// you forgot to return it
return $this->hasOne(ResolutionStatus::class, 'id', 'resolution_status_id');
}