Hi, I’m trying to do a has many through relationship but I’m having trouble.
I have three tables: orders, articles and items. An item has an order_id and an article_id which are foreign keys (among other fields). On my order model I’m trying to do this:
public function articles()
{
return $this->hasManyThrough('App\Article', 'App\Item', 'order_id', 'id');
}
But the resulting query is:
select `articles`.*, `items`.`order_id`
from `articles`
inner join `items` on `items`.`id` = `articles`.`id` where `items`.`order_id` = 1
Instead of this:
select `articles`.*, `items`.`order_id`
from `articles`
inner join `items` on `items`.`article_id` = `articles`.`id` where `items`.`order_id` = 1
How can I change the inner join condition? From items.id to items.article_id?