2013-10-21 2 views
0

MANY_MANY 관계의 제품 및 관심 분야가 포함 된 Yii 앱이 있습니다. 여기에는 다음과 같은 관계로, 분명히 매핑됩니다MANY_MANY Yii 관련 검색어 목록 제한

  'interests'=>array(self::MANY_MANY, 'Interest', 'interest_product_assignment(product_id,interest_id)'), 

난과 같이 제품 사용 CDbCriteria를 조회 할 :

$products = Product::model()->with('interests')->findAll($criteria); 

이 쿼리는 잘 작동한다. 배열에 저장된 ID가있는 특정 관심사로만 제한하려면이 코드를 확장해야합니다. 이게 가능해야한다고 생각합니다 :

$products = Product::model()->with(
     'interests', 
     array('condition' => {not_sure_what_to_put_here}) 
    )->findAll($criteria); 

나는 위의 쿼리를 완료하는 방법을 잘 모르고 있습니다. 이것에 관해서 아무것도 찾을 수 없다는 것이 아니라 내가 파헤 쳤던 것을 이해할 수 없다.

누구든지이 쿼리를 완료하는 방법을 알아 차릴 수 있습니까?

편집 내가 Telvin의 제안에 노력했습니다 무엇

: 조회 할 수있는 'IN'문을 추가하지

$products = Product::model()->with(
     'interests', 
     array('condition' => "interests_interests.interest_id IN ($selectedInterestsString)") 
    )->findAll($criteria); 

. 제공되는 ID의

답변

2

배열 : 당신의 대답 Telvin에 대한

$array_ids = array('1','24','350','4609', ....)  
$array_ids_str = '"' . implode('","', array_values($array_ids)) . '"'; 

$products = Product::model()->with(array(
     'interests'=> array('condition' => "interest_id_column IN ($array_ids_str)" 
    )))->findAll($criteria); 
+0

감사합니다. 그것은 나를 위해 일하지 않습니다. 올바른 것을 작성했는지는 확실하지 않지만 결과가 나오는 SQL에는 IN 문이 추가되지 않습니다. 나는 내가 쓴 것을 올릴 것이다. – goose

+0

EDIT 파트에서 "with"가 배열 된 후에 쿼리가 올바르지 않습니다. –

+0

나는 본다. 곧 다시 확인해 주셔서 감사합니다. – goose