You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Model_Transfer extends Model {
public $table='doc';
function init() {
parent::init();
$this->addField('amount');
$this->pmt = $this->join('payment.doc_id');
$this->pmt->hasOne('account_id', 'Model_Account');
$this->pmt->hasOne('tronsfer_payment_id', 'Model_Transfer');
}
function createPayment($account2, $amount)
{
$leg2 = clone $this;
$leg2['account_id'] = $account2->id;
$leg2['amount'] = $amount;
$leg2->save();
$this['amount'] = -$amount;
$this['transfer_payment_id'] = $leg2->id;
$this->save();
$leg2['transfer_payment_id'] = $this->id;
$leg2->save(); // BUG IN THIS LINE
}
}
The bug happens in the last save. It appears due to the cloning of a model, the related record ID gets messed up and instead of updating leg2's transfer_payment_id AD actually updates the other record.
If `clone` is replaced with 'new' then no problems appear.
Clone must be made safe.
- [ ] Implement a tes-case for thi scase
- [ ] fix
The text was updated successfully, but these errors were encountered:
I defined model like this:
The text was updated successfully, but these errors were encountered: