I am new in laravel and I am facing issue with relationships. I have three tables.
asset assetmaintenance users id id id name asset_id name inspector_id(users_id) name
I want to access all users attached with asset through assetmaintenance
, so I define relationship in asset model like:
public function users(){ return $this->hasManyThrough(TenantUser::class,AssetMaintenance::class,'asset_id','id'); }
But the query generated by eloquent is different from what I expected:
select * from `assets` where exists (select * from `users` inner join `assets_maintenance` on `assets_maintenance`.`id` = `users`.`id` where `assets`.`id` = `assets_maintenance`.`asset_id` and `username` like ?) and `isDeleted` = ? order by `id` desc
I want relation like assets_maintenance.inspector_id= users.id
but it's comparing assets_maintenance.id = user.id
.
Please suggest...