【问题标题】:Laravel connection attribute ignored with hasmanythrough使用 hasmanythrough 忽略 Laravel 连接属性
【发布时间】:2020-03-30 20:47:46
【问题描述】:

总结

我正在尝试使用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 上创建了一个问题,但它立即关闭了。

【问题讨论】:

    标签: php laravel eloquent


    【解决方案1】:

    试试

    hasMany(class with all parameter)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多