Compare commits
5 Commits
a3d9b8c4b0
...
c6c8d18ae2
Author | SHA1 | Date |
---|---|---|
b1ek | c6c8d18ae2 | |
b1ek | 1377fbb89a | |
b1ek | f9f1004b19 | |
b1ek | 04c5b7b9f1 | |
b1ek | d834d7d73e |
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use app\models\Blog;
|
||||||
|
use app\models\Comment;
|
||||||
|
use app\models\Company;
|
||||||
|
use app\models\Material;
|
||||||
|
use app\models\Subscription;
|
||||||
|
use app\models\User;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m0000001_seed extends Migration
|
||||||
|
{
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
$gen = new \Faker\Generator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Тут я не сильно оптимизировал под скорость т.к. это всего лишь 3 итерации
|
||||||
|
* и это не апи а консольная команда
|
||||||
|
*/
|
||||||
|
|
||||||
|
for ($i = 0; $i != 2; $i++) {
|
||||||
|
$user = new User();
|
||||||
|
$user->name = $gen->firstName();
|
||||||
|
$user->login = 'user_' + $i;
|
||||||
|
$user->phone = $gen->phoneNumber();
|
||||||
|
$user->passHash = Yii::$app->getSecurity()->generatePasswordHash('pass_' + $i);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$material = new Material();
|
||||||
|
$material->title = $gen->words(10, true);
|
||||||
|
$material->content = $gen->paragraph();
|
||||||
|
$material->blog_id = 0;
|
||||||
|
$material->save();
|
||||||
|
|
||||||
|
$company = new Company();
|
||||||
|
$company->title = $gen->words(2, true);
|
||||||
|
$company->website = "https://" . $gen->word() . '.com';
|
||||||
|
$company->address = $gen->address();
|
||||||
|
$company->save();
|
||||||
|
|
||||||
|
$blog = new Blog();
|
||||||
|
$blog->save();
|
||||||
|
|
||||||
|
$subscription = new Subscription();
|
||||||
|
$subscription->user_id = $user->id;
|
||||||
|
$subscription->blog_id = $blog->id;
|
||||||
|
$subscription->save();
|
||||||
|
|
||||||
|
$comment = new Comment();
|
||||||
|
$comment->material_id = $material->id;
|
||||||
|
$comment->user_id = $user->id;
|
||||||
|
$comment->content = $gen->paragraph();
|
||||||
|
$comment->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace app\models;
|
namespace app\models;
|
||||||
|
|
||||||
class Blogs extends \yii\db\ActiveRecord
|
class Blog extends \yii\db\ActiveRecord
|
||||||
{
|
{
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class Blogs extends \yii\db\ActiveRecord
|
||||||
|
|
||||||
public function getCompany()
|
public function getCompany()
|
||||||
{
|
{
|
||||||
return $this->hasOne(Companies::class, [ 'blog_id' => 'id' ]);
|
return $this->hasOne(Company::class, [ 'blog_id' => 'id' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace app\models;
|
namespace app\models;
|
||||||
|
|
||||||
class Companies extends \yii\db\ActiveRecord
|
class Company extends \yii\db\ActiveRecord
|
||||||
{
|
{
|
||||||
public $id;
|
public $id;
|
||||||
public $title;
|
public $title;
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace app\models;
|
namespace app\models;
|
||||||
|
|
||||||
class Subscriptions extends \yii\db\ActiveRecord
|
class Subscription extends \yii\db\ActiveRecord
|
||||||
{
|
{
|
||||||
public $user_id;
|
public $user_id;
|
||||||
public $company_id;
|
public $blog_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -13,7 +13,7 @@ class Subscriptions extends \yii\db\ActiveRecord
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['user_id'], 'required'],
|
[['user_id', 'blog_id'], 'required'],
|
||||||
[['id'], 'integer'],
|
[['id'], 'integer'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ class Subscriptions extends \yii\db\ActiveRecord
|
||||||
return $this->hasOne(User::class, [ 'id' => 'user_id' ]);
|
return $this->hasOne(User::class, [ 'id' => 'user_id' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCompany()
|
public function getBlog()
|
||||||
{
|
{
|
||||||
return $this->hasOne(Companies::class, [ 'id' => 'company_id' ]);
|
return $this->hasOne(Company::class, [ 'id' => 'blog_id' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -62,7 +62,6 @@ class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
|
||||||
return "user";
|
return "user";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue