这些是我的代码。
$buyuser = CHtml::encode($_POST['buyuser']);
$criteria = new CDbCriteria;
$criteria->distinct = FALSE;
$criteria->with = array('addresses'=>array('alias'=>'adres', 'together'=>true),'addresses.city'=>array('alias'=>'city', 'together'=>true));
$criteria->addCondition('t.name LIKE "'.$buyuser.'%" OR t.name LIKE "% '.$buyuser.'%" OR t.lastname LIKE "'.$buyuser.'%" OR t.lastname LIKE "% '.$buyuser.'%" OR adres.store LIKE "'.$buyuser.'%" OR adres.store LIKE "% '.$buyuser.'%" OR city.name LIKE "'.$buyuser.'%" OR city.name LIKE "% '.$buyuser.'%"');
$users = Users::model()->findAll($criteria);
它有效,但我想在city.name或lastname或store为1时看到重复的记录。 我需要所有地址。
答案 0 :(得分:0)
我更改了findAll中的基表及其答案。
$buyuser = CHtml::encode($_POST['buyuser']);
$criteria = new CDbCriteria;
$criteria->distinct = FALSE;
$criteria->with = array('user'=>array('together'=>true),'city'=>array('together'=>true));
$criteria->addCondition('user.name LIKE "'.$buyuser.'%" OR user.name LIKE "% '.$buyuser.'%" OR user.lastname LIKE "'.$buyuser.'%" OR user.lastname LIKE "% '.$buyuser.'%" OR CONCAT(user.name," ",user.lastname) LIKE "'.$buyuser.'%" OR CONCAT(user.name," ",user.lastname) LIKE "% '.$buyuser.'%" OR t.store LIKE "'.$buyuser.'%" OR t.store LIKE "% '.$buyuser.'%" OR city.name LIKE "'.$buyuser.'%" OR city.name LIKE "% '.$buyuser.'%"');
$addresses = Addresses::model()->findAll($criteria);