CActiveRecord Many to Many example?

Is there some example source somewhere show how the many to many CActiveRecord relationship works? A look at how the database is set up would be great too.

I setup my database EXACTLY like this:


Here is my relationship block:

Here is the create action in the controller:

When I create a new work entry no associative tables are created, i couldn't find anything on that page that says how to accomplish this. Is Yii suppose to do this automagically or do I need to write custom getters and setters?

You need to save related objects manually.

thanks qiang, just wanted to make sure i wasn’t reinventing the wheel!  8)

so this is how i am currently updating the assoc table, not really a big fan of the way it is currently being done. does anyone have some suggestions?

If you want less code in your Controller you could add a method like setSkills(array($skillId1, $skillId2, …)); to your Worker model. In that method you delete all old skills and save the new ones.