【发布时间】:2014-04-28 12:03:30
【问题描述】:
我的代码:
$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'=>'firstname',但它仅从 User 表而不是从 user_profiles 表加载数据
我想要来自user 和userProfile 表的数据。
【问题讨论】:
-
不就是
Users的拼写错误吗?不是只有User在你activedataprovider吗? -
它的工作,不是拼写问题?
-
显示 userProfiles 关系
-
@Alex, 'userProfiles' => 数组(self::HAS_ONE, 'UserProfile', 'user_id'),
标签: php mysql yii cactivedataprovider