Answer the question
In order to leave comments, you need to log in
Why doesn't Yii2 ActiveRecord Model delete?
I don't understand why Call to a member function delete() error
Here is the model
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
/**
* UserToSection model
*
* @property integer $id
* @property integer $user_id
* @property integer $section_id
*/
class UserToSection extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id]);
}
}
$section = UserToSection::findAll([
'user_id' => \Yii::$app->user->getId()
]);
print_R($section);
$section->delete();
Answer the question
In order to leave comments, you need to log in
I asked myself, I answer myself
$section = UserToSection::deleteAll([
'user_id' => \Yii::$app->user->getId()
]);
findAll returns an array of objects, so
either like this:
$section = UserToSection::findAll(['user_id' => \Yii::$app->user->getId()]);
foreach($section as $one){
$one->delete();
}
UserToSection::deleteAll([
'user_id' => \Yii::$app->user->getId()
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question