【发布时间】:2013-10-21 21:29:43
【问题描述】:
我有一个 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”语句。
【问题讨论】:
标签: php sql yii many-to-many