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;
         }
     }
 }
Example #2
0
 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();
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserStat()
 {
     return $this->hasOne(UserStat::className(), ['user_id' => 'id']);
 }