Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii CActiveDataProvider数据未从联接表加载_Php_Mysql_Yii_Cactivedataprovider - Fatal编程技术网

Php Yii CActiveDataProvider数据未从联接表加载

Php Yii CActiveDataProvider数据未从联接表加载,php,mysql,yii,cactivedataprovider,Php,Mysql,Yii,Cactivedataprovider,我的代码: $criteria = new CDbCriteria(); // $criteria->select = array("id"); $criteria->with = array('userProfiles'=>array( 'select'=>'firstname' )); $criteria->together = true; $criteria->condition = "firstname like '%$q%' "

我的代码:

$criteria = new CDbCriteria();

//  $criteria->select = array("id");

$criteria->with = array('userProfiles'=>array(
    'select'=>'firstname'
));
$criteria->together = true;

$criteria->condition = "firstname like '%$q%' "
        . "and (user_id not in (select id2 from friends where id1=$user_id) "
        . "and user_id not in (select id1 from friends where id2=$user_id))";

$dataProvider = new CActiveDataProvider("Users", array(
    'criteria' => $criteria
));

return $dataProvider;
注:

1-
userProfiles
关系在用户模块中定义

问题:

尽管提供了select atribute
“select”=>“firstname”


我需要来自
user
userProfile
表的数据。

关系self::HAS\u一个不能与主查询一起执行,请尝试使用join

$criteria->select=“*,user_profiles.firstname firstname”; $criteria->join='user_profiles ON user_profiles.user_id=users.id'

类似这样,但您应该在用户AR中创建firstname字段来检索它

或者将关系更改为有多个并检查数组的第一个实体

:是否应强制与此关系关联的表与主表和其他表合并。此选项仅对“有很多”和“很多”关系有意义

因为您不能编写只为每个加入记录提供一条记录的查询

SELECT * FROM main
INNER JOIN slave ON (slave.main_id = main.id limit 1) // will not work);

这不是简单的用户拼写错误吗?在你的activedataprovider中,它不仅仅是
用户
?它的工作,而不是拼写问题?显示用户配置文件relation@Alex,'userProfiles'=>数组(self::HAS_ONE,'UserProfile','user_id'),