2017-12-05 31 views
1

두 개의 테이블 product_price 및 trade_channel을 결합해야했습니다. 내부 결합을 사용할 때
product_price의 ID는 제거됩니다.내부 laravel 누락 P

여기

DB::table('product_price')->where('product_id',$id)->where('action','customer_price') 
     ->join('customers','product_price.action_id','=','customers.id') 
     ->get(); 

답변

2

실제로 모든 열을 사용할 필요가없는 열을 선택하는 것이 좋습니다.

당신은 당신이 뭔가 할 수 customer_price 테이블에서 PRODUCT_PRICE 테이블 만 고객 ID의 모든 열을 필요로이 경우 가정 해 보겠습니다

: 당신은 어떤 열을 선택할 수 있습니다

DB::table('product_price') 
->select(['product_price.*','customer_price.id AS customer_id']) 
->where('product_price.product_id',$id) 
->where('product_price.action','customer_price') 
->join('customers','product_price.action_id','=','customers.id') 
->get(); 

을하지만, 조인의 별칭을하는 것이 좋다 이 경우 테이블 열은 customer_price이므로 두 테이블 모두에 동일한 이름 열이 있으면 혼란을주지는 않습니다.

행운을 빌어 요

+0

이 광고는 나에게 지식을 추가했습니다. –

1

그래서 그냥 다른 이름으로 PRODUCT_PRICE 아이디를 인쇄는 PRODUCT_PRICE ID가 고객의 ID로 대체 될 것이다

DB::table('product_price') 
->select('*','product_price.id AS product_price_id') 
->where('product_id',$id) 
->where('action','customer_price') 
->join('customers','product_price.action_id','=','customers.id') 
->get(); 

을 시도 내 코드입니다. 도움이 되길 바랍니다.