Home > Backend Development > PHP Tutorial > yii relations求救

yii relations求救

WBOY
Release: 2016-06-23 14:24:11
Original
884 people have browsed it

数据库是 mysql myisam 

现有已表 train 培训表

train_people 参加培训的人员表

一个train对应多个 train_people 通过 train的主键 train_id关联的 train_people 里面也有个train_id

在Train model里面

public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
       return array(
            'people'=>array(self::HAS_MANY, 'TrainPeople', 'train_id'),
       );
   }

这样写的

查询语句



$model = new Train();
        $model_user = new User();
        $criteria = new CDbCriteria;
        //$criteria->condition = "";
        $criteria->order = 'add_time DESC';
        $criteria->select = '*';
        $count = $model->count($criteria);
        $pager = new CPagination($count);
        $pager->pageSize = 10;
        $pager->applyLimit($criteria);
        $lists = $model->with('people')->findAll($criteria);
        var_dump($lists->people);
结果为 空 数据库里我添加数据了 请问这是什么情况


回复讨论(解决方案)

Yii::app()->db()->createCommand()->select(列)->from(表)->where()->limit()->order()->queryAll()
Copy after login
Copy after login

Yii::app()->db()->createCommand()->select(列)->from(表)->where()->limit()->order()->queryAll()
Copy after login
Copy after login

虽然不是我想要的,问题已经解决了,这么长时间只有你回答感。非常感谢没有鄙视像我这样问一些弱智的问题

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template