Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

Hi there,

company
	id
	name
users
	id
	name
roles
	id
	name
company_user
	company_id
	user_id
role_user
	user_id
	role_id

so I have

class Company
	public function roles()
    	{
        	return $this->hasManyThrough('RoleUser', 'CompanyUser', 'company_id', 'user_id');
    	}

But $company->roles() does not work :(, i got

Column not found: 1054 Unknown column 'company_user.id' in 'on clause' (SQL: select `role_user`.*, `company_user`.`company_id` from `pet_user` inner join `company_user` on `company_user`.`id` = `role_user`.`user_id` where `company_user`.`company_id` = 1)

The query asks for company_user.id and it should be company_user.user_id

Any clues be many appreciate

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ricardo ricardo Joined 19 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.