support of composite key by yii CRUD

Does the model class support composite primary key?

If so please explain me how does it do.

If not what is the second chance of it.

Please help me

If I am not mistaken, it can’t implement composite key for CRUD. In order to use Gii generator power to generate CRUD, you must create a field for primary key. What I usually do is creating a field name ‘id’ as primary key. While the other field which is used to be composite key are changed to UNIQUE…

You can create your table with “id” as primary key. Then, you can use gii for create model class. Last but not least, you have to delete id field, and set your composite super key. Dont work in all cases. But the right way is junxiong’s way. If you have a super key (with more than one field) the better thing to do is to refactor your database.

Thanks for the idea.

After experiencing this issue using yii 1.1.10, I created a free online CRUD generator that works for tables with composite primary keys. Anybody having this problem can use the generator at http://handsoncoding.net

Currently the generated views look and function just like views that are created using gii. I will add in error handling though later on to prevent the ugly errors that appear when trying to delete a row from a table that is referenced by a child in another table.

I hope this is a time saver for everyone.

I tried using your tool and it generated the code without any errors…

Now I just have to get it running in the app. Anyway, thanks for the tool, I’m a newb in yii and

this tool seems to have shed light with the problem about the composite keys in yii.

Thanks again!

Cheers!