コード例 #1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $wallet = new Wallet();
     $wallet->name = $this->name;
     $wallet->setUser($this->_user);
     if ($wallet->save()) {
         $walletAmount = new WalletAmount();
         $walletAmount->wallet_id = $wallet->id;
         $walletAmount->currency_id = $this->_currency->id;
         $walletAmount->amount = (double) $this->amount;
         if ($walletAmount->save()) {
             return [array_merge($wallet->toArray(), ['amounts' => $wallet->getAmounts()->all()])];
         }
     }
     return false;
 }
コード例 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWalletAmounts()
 {
     return $this->hasMany(WalletAmount::className(), ['currency_id' => 'id']);
 }