Actioncreate/update For Related Tables

I have three tables: Contact, Category, and Categories. The table Category contains details of what type of contact a Contact row is, and a Contact can have many Categories (could, say, be a supplier and a customer), and similarly there could be many Contacts who belong to the same Category, so as is usual in such cases, I split the many-many out into a separate table, ContactCategories.

Assuming I want a user to be able to create a Contact and assign categories, how should I go about it? In fact I think I’ve actually got that solved (maybe incorrectly), but what about editing that contact (particularly when the assigned categories change)?

At the moment when Contact->actionUpdate is called and the model is loaded, the resulting form doesn’t have any content. I suspect, from doing a var_dump that the model isn’t including the data from the related tables. Where have I gone wrong?

Hi, yii is not natively very easy with multi-model on form.

For multi-model, i used an extension, but i thonk there are another possibility.

Tell me about it! :rolleyes:

I’ve managed to get the related tables’ data into the model

    public function loadModel($id)


        $model = Contact::model()->with(array('person', 'categories'))->findByPk($id);



but it still doesn’t populate the view. I’m suspecting I need to do something with some of my code called by ->render() but I don’t know where or what.