Saving Non-Model (Relation) Records To Db

I have an association table tbl_user_bu_assignment which stores the many to many relationship of users to their business units.

I am following this article:

In here, Larry has got the association table as an actual model, and in the controller code stores the MODEL as such:

if($model->save()) {

            foreach ($_POST['Posts']['categories'] as $categoryId) {

                $postCategory = new PostsCategories;

                $postCategory->postId = $model->id;

                $postCategory->categoryId = $categoryId;

                if (!$postCategory->save()) print_r($postCategory->errors);

Since I don’t have a model defined for my association table (as per the user_project_assignment table in the Agile Development yii book which also doesn’t define a model for association tables),

how can I save a record in my assoc table to store the relationship data?

any help much appreciated


I’d recommend using one of the great many-many extensions. You don’t need to have a model for your association table.