voskobovich / yii2-many-to-many-behavior

This behavior soon will be DEPRECATED. See the link:

Home Page:https://github.com/voskobovich/yii2-linker-behavior

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support multiple ManyToMany fields that are using the same junction table

kop opened this issue · comments

I have a model where I need to use ~10 ManyToMany fields that are using the same junction table but different additional field in junction table.
Current behaviour does not support such usage, because of this lines of code:

// Remove old relations
$connection->createCommand()
    ->delete($junctionTable, [$junctionColumn => $primaryModelPk])
    ->execute();

This code is located inside the foreach, so each time new links are inserted to the junction table, it removes previous inserts.

This code block needs to be moved upper in the code, before foreach even starts.