hasManyThrough中有错误

时间:2016-08-09 19:57:24

标签: laravel relation

在Laravel中使用hasManyThrough时遇到问题。 我的桌子:

enter image description here

在Branch模型中我有这个

public function works()
{
    return $this->hasManyThrough('App\Work', 'App\Field','branch_id','field_id');
}

在路线中我有这个

$b= App\Branch::all()->first();
dd($b->works()->get());

并收到此错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fields.branch_id' in 'field list' (SQL: select `works`.*, `fields`.`branch_id` from `works` inner join `fields` on `fields`.`id` = `works`.`field_id` where `fields`.`branch_id` = 1)

1 个答案:

答案 0 :(得分:0)

在多对多关系中没有使用renderArray.push(( <View ref={(node) => this.refsViewArray.push(node)}> <Animated.Image ref={(node) => this.refsImageArray.push(node) } /> </View> )); 的任何规定。但是您可以使用hasManyThrough()来实现此目的,或者您可以将以下函数添加到您的BaseModel中,如forum中所示。

DB::raw()