public function safeUp() { foreach (User::find()->orderBy('id')->all() as $user) { $stat = new UserStat(); $stat->user_id = $user->id; $stat->createCurrentData(); if (!$stat->save()) { return false; } } }
public function updateUserStat() { if (!($stat = UserStat::findOne(['user_id' => $this->user_id]))) { $stat = new UserStat(); $stat->user_id = $this->user_id; } $stat->createCurrentData(); $stat->save(); }
/** * @return \yii\db\ActiveQuery */ public function getUserStat() { return $this->hasOne(UserStat::className(), ['user_id' => 'id']); }