繁体   English   中英

MANY_MANY Yii查询限制相关记录列表

[英]MANY_MANY Yii query limiting to list of related records

我有一个Yii应用程序,其中包含MANY_MANY关系的产品和兴趣。 显然,这些映射具有以下关系:

            '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的建议:

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

不向查询添加“IN”语句。

提供的ID数组:

$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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM