staudenmeir / belongs-to-through

Laravel Eloquent BelongsToThrough relationships
MIT License
1.15k stars 88 forks source link

through table is not joined as I want. #26

Closed gracefullight closed 5 years ago

gracefullight commented 7 years ago
product
- idx_product  PK

sale_product
- idx_sale_product PK
- idx_sale

sale
- idx_sale PK

I've tried a lot and following logic is the closest.

// App\Models\Product

public function sale() {
  return $this->belongsToThrough('App\Models\Sale', 'App\Models\SaleProduct', null, '', [
     'App\Models\SaleProduct' => 'idx_sale_product',
     'App\Models\Sale' => 'idx_sale',
  ]);
}

However, the result of the query execution is not what I wanted.

select `sale`.* from `bp_sale` 
left join `sale_product` on `sale`.`idx_sale` = `sale_product`.`idx_sale` 
left join `product` on `sale_product`.`idx_sale` = `product`.`idx_sale_product` 

How can i change sale_product.idx_sale to sale_product.idx_sale_product ? (third line) It's too harsh for me

znck commented 7 years ago

Please send a PR with a failing test case.

staudenmeir commented 5 years ago

Are you still having this issue?