A
A
Alexander Nevsky2018-11-09 07:57:52
Yii
Alexander Nevsky, 2018-11-09 07:57:52

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

1 answer(s)
D
Dmitry Bay, 2018-11-09
@soy4er

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 question

Ask a Question

731 491 924 answers to any question