首页 > 解决方案 > 使用 hasmanythrough 忽略 Laravel 连接属性

问题描述

概括

我正在尝试使用hasManyThrough与来自不同连接的表的关系。

问题描述:

定义hasManyThrough关系时,protected $connection忽略该属性。

重现步骤:

创建以下模型(缩写代码)

class Resource extends Model
{
    protected $connection = 'tcollect'

    public function absences()
    {
        return $this->hasManyThrough('ARM\TargetHoraire\Absence', 'ARM\Tcollect\ICO\ICOExternalReference', 'RecordID', 'ResourceID', 'ID', 'ExternalKey');
    }
}
class Absence extends Model
{
    protected $table = 'Absences';
    protected $connection = 'punch';
}

class ICOExternalReference extends Model
{
    protected $table = 'ICOExternalReferences';
    protected $connection = 'tcollect';
}

然后调用资源模型上的关系 $resource->absences;

请注意ICOExternalReference$connection 属性被忽略。它尝试使用punch连接中的 ICOExternalReference。

问题

我的代码有问题还是有解决这个问题的解决方法?我在框架 repo 上创建了一个问题,但它立即关闭了。

标签: phplaraveleloquent

解决方案


尝试

hasMany(class with all parameter)

推荐阅读