Gii and many to many - inserting & updating records


I used Gii to generate my tables and then added manually code in the getters of the models using viaTable function.

It works great for displaying data and for searching.

My question is how do I insert new records?

Assume my data model has users and projects table and models with a link table called user_projects.

I would like to add new projects to a user through the user create form generated by gii using the checkboxlist function.

Many thanks

I hope this wiki article will be of some help.

Thanks for the article. I’m not sure I understand how to integrate it with my code assuming I am using Gii to generate my models. Could you give me a direction?


Well, I got nothing special to add to the wiki article.

3 out of 4 models in the article should have been generated by Gii for you. Just add the 4th and write your own code.