refactor: use only blog_id on company and user for foreign keys
This commit is contained in:
parent
c3d489965c
commit
a3d9b8c4b0
|
@ -5,8 +5,6 @@ namespace app\models;
|
|||
class Blogs extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $id;
|
||||
public $user_id;
|
||||
public $company_id;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -21,12 +19,12 @@ class Blogs extends \yii\db\ActiveRecord
|
|||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne(User::class, [ 'id' => 'user_id' ]);
|
||||
return $this->hasOne(User::class, [ 'blog_id' => 'id' ]);
|
||||
}
|
||||
|
||||
public function getCompany()
|
||||
{
|
||||
return $this->hasOne(Companies::class, [ 'id' => 'company_id' ]);
|
||||
return $this->hasOne(Companies::class, [ 'blog_id' => 'id' ]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ class Companies extends \yii\db\ActiveRecord
|
|||
public $title;
|
||||
public $website;
|
||||
public $address;
|
||||
public $blog_id;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -17,7 +18,7 @@ class Companies extends \yii\db\ActiveRecord
|
|||
return [
|
||||
[['id', 'title', 'website', 'address'], 'required'],
|
||||
[['title', 'website', 'address'], 'string'],
|
||||
[['id'], 'integer'],
|
||||
[['id', 'blog_id'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue