Answer the question
In order to leave comments, you need to log in
How to update 1 cell in Yii2?
I have a model, it has required on several elements.
But in one form, I want to update only 1 cell - rating, but the validation fails. Please tell me how to solve the problem.
$booksRating = Books::find()->where(['id' => $id])->select(['rating'])->one();
$booksRating->rating = round(array_sum($ratings)/count($ratings), 1);
if ($booksRating->update()) {
print_r($booksRating->rating);
} else {
print_r($booksRating->errors);
}
Answer the question
In order to leave comments, you need to log in
Most likely, required is some kind of tag that needs to be filled in every time.
In your specific case, use updateAttributes(); it works without validation.
For other moments - use scripts.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question