Best way to work with Many-To-Many relations

Almost in every project we have many-to-many ralations.

For example:





author

--------------

id

name


book

--------------

id

title


author_to_book

--------------

id

author_id

book_id




I want to work with such a structure such a way:





$author = Author::findOne($id);

$author.bookIds = [12, 33];

$author.save();




I have found many "Many-to-Mamy Behavior" extensions on github. One of them: https://github.com/yii2tech/ar-linkmany (from yii2 core team guy). But what is the best modern solution for it?

Is there a core yii2 solution without external extensions?

Maybe I should use link() for it?

Can you use via or viatable?

and in the controller yo should use loadMultiple()

Yes, I can use viaTable() for find and getting data. But how I can easy update relative records?

How I can bind several books to author in one line of code?

Have a look at the guide: http://www.yiiframework.com/doc-2.0/guide-input-tabular-input.html