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; }
/** * @return \yii\db\ActiveQuery */ public function getWalletAmounts() { return $this->hasMany(WalletAmount::className(), ['currency_id' => 'id']); }