Answer the question
In order to leave comments, you need to log in
How to check if a record is found in Yii2?
I make a selection of a non-existent record, the result is true because into the array is not empty, it contains other fields.
Next, you will be prompted to delete the entry.
$followRecord = Follow::find([
'userId' => 111,
'onUserId' => 777
])->one();
if($followRecord)
//Удаление
Answer the question
In order to leave comments, you need to log in
If you have a "true result", then it means that the one() function found the same record. One() returns either an array of the found entry's attributes, or NULL (`null` will be returned
if the query results in nothing). So check your database query.
And yes, I usually check like this:
$followRecord = Follow::find(['userId' => 111, 'onUserId' => 777])->one();
if ($followRecord instanceof Follow) {
// запись найдена - удаляем ???
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question