Actually, the code itself

$trailers=Trailers::findOne(['id_film'=>$film->id]); if(isset($trailers)) { $trailers->description = $video; $trailers->id_film = $film->id; if($trailers->save()){}else{var_dump($trailers->getErrors());}; } 

in the debugger it shows that such a record finds but does not save. Why?

    1 answer 1

    Does var_dump($trailers->getErrors() ? There may be several cases: the model failed validation (try calling $trailers->validate() ), the mysql user cannot write to the database, etc., etc. .P.

    PS It is not very correct to call the $trailers variable when you look for a single entry using findOne() . Call it $trailer , then after a couple of dozen lines of code it will be much more obvious.

    • no getErrors does not work if the code is done like this $ trailer = new Trailers (['description' => $ video, 'id_film' => $ film-> id,]); $ trailer-> save (); } then the new one will remain. - Sergalas
    • the name doesn't matter now - Sergalas
    • one
      No, the name does not matter, it is so for the future. - Zhukov Roman