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:


UserID (primary key)



RolesID (foreign key for Rolesdetails - RolesTableID)



RolesTableID (PK)


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:

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: