1

我遇到了一个小问题,我需要你的帮助。我想连接两个表,但连接还有其他条件,而不仅仅是外键。我尝试设置条件参数,但它在我的查询中创建了一个 WHERE,这将导致我的主表将被过滤而不是连接的表。

'dokumentumok' => array(self::HAS_MANY, 'Fileuploader', 'foreign_id', 'joinType' => 'LEFT JOIN', 'condition' => "(dokumentumok.fileuploader_type='nyomtatvany') AND dokumentumok.fileuploader_deleted = 0"),

这将是条件->

'condition' => "(dokumentumok.fileuploader_type='nyomtatvany') AND dokumentumok.fileuploader_deleted = 0
4

2 回答 2

6

替换conditionon

'dokumentumok' => array(self::HAS_MANY, 'Fileuploader', 'foreign_id', 
  'joinType' => 'LEFT JOIN', 
  'on' => "(dokumentumok.fileuploader_type='nyomtatvany') 
  AND dokumentumok.fileuploader_deleted = 0"
)

另见:http ://www.yiiframework.com/forum/index.php/topic/10185-using-relations-and-conditions/

于 2013-02-21T07:05:24.540 回答
1

或者例如。

关于

'dokumentumok' => array(self::HAS_MANY, 'Fileuploader', 'foreign_id');

并获取模型

YouModelName::model()->with(array('dokumentumok' => array('on' => "(dokumentumok.fileuploader_type='nyomtatvany') AND dokumentumok.fileuploader_deleted = 0")))->findAll();

于 2014-06-04T17:23:29.657 回答