arogachev/yii2-many-to-many

How to delete data from the main table as well as in the junction table?

neerajs046 opened this issue · 2 comments

Hello @arogachev your extension really help me a lot. But when I am deleting the user it gives me Integrity constraint violation. How to fix this issue.

To delete data, you just need to modify editable attribute value.

For example, if this was initial value:

$model = new Test;
$model->getManyToManyRelation('users')->fill();
var_dump($model->editableUsers) // [1, 2]

to delete user with id = 2, you just remove it from array:

$model->editableUsers = [1];
$model->save();

As for integrity constraint violation error, please provide your code and according database tables structure.

No further feedback, closing this.