我有findByAttributes()
功能与userRemoteIdentities
模型
$record = User::model()->with('userRemoteIdentities')->findByAttributes(
array('email' => $remoteProfile->email),
array(
'condition' =>'provider = :provider AND identifier = :identifier',
'params'=>array(':provider'=> strtolower($_GET['provider']), ':identifier'=> $remoteProfile->identifier)
)
);
问题是它使用AND
WHERE (`t`.`email`=:yp0 AND (provider = :provider AND identifier = :identifier)
我如何才能使用这样的OR
?
WHERE (`t`.`email`=:yp0 OR (provider = :provider AND identifier = :identifier))
或者有更好的方法吗?
答案 0 :(得分:1)
在addColumnCondition中使用第二个和第三个参数
在模型中创建函数
public function yourFunctionName($provider, $remoteProfile){
$criteria = new CDbCriteria;
$criteria->with = 'userRemoteIdentities';
$criteria->addColumnCondition(['email' => $remoteProfile->email]);
$criteria->addColumnCondition(['provider' => strtolower($provider), 'identifier' => $remoteProfile->identifier], 'AND', 'OR');
return $this->findAll($criteria);
}
呼叫
$record = User::model()->yourFunctionName($_GET['provider'], $remoteProfile);
P.S。我使用短数组语法。