Help with many to many


I have created 2 tables, one for posts, one for categories via mysql benchmark.

When I created a relation many to many it created a third table called "categories_has_posts".

Now in Gii, what do I do? Shall I generate a crud for this table or not?

Because at the moment I am stuck, I create the model controlller and crud for the POSTS and for the Categories. On the posts page, I call via a dropdown menu all the categories. When I create a post, I can now choose a category but that middle table seems not to be in use at all, no data is going inside.

How does it works with many to many relations please as I am totally lost on that one.



Look at the Junction Table to the guide:

Previously, I also posted some example of how to modify a model to save it with related records:

And by the way I’d suggest to name your tables in singular form (“post”, “category”) and the junction table “post_category”. See

Thank you so much for the reply. Will check every out and post back if I do not understand something.

Thanks again!