Answer the question
In order to leave comments, you need to log in
Lack of synchronization of data from the database when changing - what to do?
In the Domain model, there is such a relationship with users:
public function getUser() {
return $this->hasOne(User::className(), ['id' => 'userId']);
}
$domains = Domain::find()->where(['userId' => 4])->all();
foreach ($domains as $i => $domain) {
if ($i == 0) {
$domain->user->updateCounters(['balance' => -10]);
echo 'UserId4 Balance: ' . $domain->user->balance . "\n";
} elseif ($i == 1) {
echo 'UserId4 Balance: ' . $domain->user->balance . "\n";
exit;
}
}
UserId4 Balance: -10
UserId4 Balance: -10
UserId4 Balance: -10
UserId4 Balance: 0
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question