Commit ce92ed25 authored by xiabin's avatar xiabin

修改model

parent e1ac486a
......@@ -114,6 +114,10 @@ class Course extends \yii\db\ActiveRecord
return $result === NULL ? FALSE : TRUE;
}
/**
* @param $id
* @return array|null|\yii\db\ActiveRecord
*/
public static function getBasicData($id)
{
$query = self::find();
......@@ -137,7 +141,7 @@ class Course extends \yii\db\ActiveRecord
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
if ($count > 0) {
$data = self::find()->select('id,user_id,price,name,intro,preview_pic,recommend,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers', 'favorites')->asArray()->all();
$data = self::find()->select('id,user_id,price,name,intro,preview_pic,recommend,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers')->asArray()->all();
}
return [
'count' => $count,
......@@ -164,15 +168,4 @@ class Course extends \yii\db\ActiveRecord
{
return $this->hasMany(Teacher::className(), ['id' => 'teacher_id'])->viaTable(CourseTeacher::tableName(), ['course_id' => 'id']);
}
public function getComments()
{
$tableA = Comments::tableName();
return $this->hasMany(Comments::className(), ['user_id' => 'user_id', 'course_id' => 'id']);
}
public function getFavorites()
{
return $this->hasMany(Favorite::className(), ['user_id' => 'user_id', 'course_id' => 'id']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment