yii with 关联查询失灵 [ 新手入门 ]
两个表:表一 grade(id,title)含义是主键和年级名称
表二 classroom(id,title,grade_id)含义是主键,班级名称,所在年级
我在classroom的模型中定义了关系:'nianji' => array(self::BELONGS_TO, 'Grade', 'grade_id')
,
然后在classroom的控制器使用$data=Classroom::model()->with('nianji')->findAll();
echo CJSON::encode($data);exit;
进行查询,结果是:
[{"id":"1","title":"344","grade_id":"2"},{"id":"2","title":"345","grade_id":"2"},{"id":"3","title":"346","grade_id":"2"},{"id":"4","title":"347","grade_id":"2"},{"id":"5","title":"348","grade_id":"2"},{"id":"6","title":"349","grade_id":"2"},{"id":"7","title":"350","grade_id":"2"},{"id":"8","title":"351","grade_id":"2"},{"id":"9","title":"352","grade_id":"2"},{"id":"10","title":"353","grade_id":"2"},{"id":"11","title":"354","grade_id":"2"},{"id":"12","title":"355","grade_id":"2"},{"id":"13","title":"356","grade_id":"2"},{"id":"14","title":"357","grade_id":"2"},{"id":"15","title":"358","grade_id":"2"},{"id":"16","title":"359","grade_id":"2"},{"id":"17","title":"362","grade_id":"1"}]
表grade中的数据没有获取到,怎么回事? [attach]885[/attach]
共 6 条回复
sxtuwy 山西
注册时间:2011-07-24
最后登录:2013-06-04
在线时长:0小时0分
最后登录:2013-06-04
在线时长:0小时0分
- 粉丝8
- 金钱1645
- 威望0
- 积分1645