Help with many to many

Hello,

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.

Thanks,

Ben

Look at the Junction Table to the guide: http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relations-with-junction-table

Previously, I also posted some example of how to modify a model to save it with related records: http://www.yiiframework.com/forum/index.php/topic/62030-whats-the-simple-straightforward-way-to-save-a-many-to-many-relation/page__p__275073#entry275073

And by the way I’d suggest to name your tables in singular form (“post”, “category”) and the junction table “post_category”. See http://stackoverflow.com/questions/338156/table-naming-dilemma-singular-vs-plural-names

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

Thanks again!

Ben