Single Form Multiple Model

Hi people

I very new to yii and need some help. I have a very simple demo app, where there are two tables:

USER


UserID (primary key)

Username

Password

RolesID (foreign key for Rolesdetails - RolesTableID)

And

ROLESDETAILS


RolesTableID (PK)

Roles

Its a very simple form with three fields - username, password and drop-down of roles. I want to create a new user and insert the data into both the tables.

I followed the following article:

http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/

However, not able to make any headway. I believe there is some issue with table integrity. The second table, Rolesdetails, has RolesTableID is foreign key of RolesID in User table.

I think I need to insert in Table RolesDetails first and look-up the ID and insert in to User table. All in one transaction. Looking at the blank wall as to how I should go about it. Any help would be great and superbly appreciated!!!

Thank in advance!

Hi prateek13!

You can use ActiveRecord Relation Behavior for your request. You can see extention at url: github.com/yiiext/activerecord-relation-behavior