我有4个数据库表:
用户 :ID,用户名,密码
楼层 :ID,用户ID,姓名
客房 :ID,楼层,名称
学生 :ID,房间名称,活跃
如何返回CActiveDataProvider为后续SQL命令?
SELECT * FROM `student` WHERE `student`.`active` = 0 AND `student`.`room` IN (SELECT `room`.`id` FROM `room` WHERE `room`.`floor` = (SELECT `floor`.`id` FROM `floor` WHERE `floor`.`userid` = $userid))
我试过了:
$model = Student::model()->findAllBySql("SELECT * FROM student WHERE active = 0 AND room IN (SELECT id FROM room WHERE floor = (SELECT id FROM floor WHERE user = $user))");
return new CActiveDataProvider($model);
但响应:
致命错误:调用一个成员函数getDbCriteria()一个非对象在X:的appserv \ WWW \框架\网络\上线225 CActiveDataProvider.php