forked from cebe/yii2-openapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPost.php
69 lines (61 loc) · 2.17 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* This file is generated by Gii, do not change manually!
*/
namespace app\models\base;
/**
* A blog post (uid used as pk for test purposes)
*
* @property string $uid
* @property string $title
* @property string $slug
* @property int $category_id Category of posts
* @property bool $active
* @property string $created_at
* @property int $created_by_id The User
*
* @property \app\models\Category $category
* @property \app\models\User $createdBy
* @property array|\app\models\Comment[] $comments
*/
abstract class Post extends \yii\db\ActiveRecord
{
public static function tableName()
{
return '{{%blog_posts}}';
}
public function rules()
{
return [
'trim' => [['title', 'slug', 'created_at'], 'trim'],
'active_default' => [['active'], 'default', 'value' => false],
'required' => [['title', 'category_id', 'active'], 'required'],
'title_string' => [['title'], 'string', 'max' => 255],
'slug_string' => [['slug'], 'string', 'min' => 1, 'max' => 200],
'active_boolean' => [['active'], 'boolean'],
'created_at_date' => [['created_at'], 'date', 'format' => 'php:Y-m-d'],
'title_unique' => [['title'], 'unique'],
'slug_unique' => [['slug'], 'unique'],
'category_id_integer' => [['category_id'], 'integer'],
'category_id_exist' => [['category_id'], 'exist', 'targetRelation' => 'category'],
'created_by_id_integer' => [['created_by_id'], 'integer'],
'created_by_id_exist' => [['created_by_id'], 'exist', 'targetRelation' => 'createdBy'],
];
}
public function getCategory()
{
return $this->hasOne(\app\models\Category::class, ['id' => 'category_id']);
}
public function getCreatedBy()
{
return $this->hasOne(\app\models\User::class, ['id' => 'created_by_id']);
}
public function getComments()
{
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'uid'])->inverseOf('post');
}
public function getComment()
{
return $this->hasOne(\app\models\Comment::class, ['post_id' => 'uid'])->inverseOf('post');
}
}