【发布时间】:2017-01-20 11:57:17
【问题描述】:
嘿,所以我应该首先说我得到了这个数据库来使用。所以不确定他们使用的是什么关系。我最终需要做的是获取分配给文章的类别名称。
基本上看起来像这样articles <> article_categories <> categories
article_categories 是连接器
文章
|ID|header|body|ect...|
类别
|ID|parent_group|name|
article_categories
|article_id|category_id|
所以我认为可能是hasManyThrough,但只有错误。这也可能是我的论点做错了。
我首先尝试的是在文章模型内部(由此出现错误)
public function category(){
return $this->hasManyThrough('App\categories' , 'App\article_categories' ,'article_id' , 'category_id');
}
希望我解释一下我的情况。我需要使用has many through 还是我过于复杂了?
-谢谢
【问题讨论】:
标签: php laravel model rss relationship