composite primary key not supported by crud command

mark,same confused,should i create views&controller by myself? :lol:

I too would really appreciate guidance as to the best approach to handle my data modeling and any alterations needed once GII generates the model and crud. This is holding up my project!

I am leaning toward the solution in post#10, where I could add an unnecessary id (as an auto-increment primary key) in terms of my data model, then add a unique index to the two fields that I would like to be the composite primary key. Obviously this is not ideal, but I love Yii for everything else I have encountered in my first major project using it.

If anyone has found more documentation or where all the places in the Gii generated code need to be updated, I would greatly appreciate if you share!

I wonder what the plans are for this feature in Yii 2.0 …

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.

Brilliant utility - thanks! Worked first time.

Composite Primary Key - CRUD Yii

Yes , real world applications has lots of composite keys.This is not a big deal to implement CRUD for composite keys. YII has all other feature , I wonder why they drop this importamt feature. Hopefully at least in a next release.

Thanks Pat for your very helpfull generator !

Brilliant! Is it still maintained?

I can’t even count how many times I’ve come across a thread where a user is making an extremely valid point or bringing attention to a serious design flaw, just to have Qiang respond with basically the exact same thing. He always says, in one way or another, to “keep it simple”. However, lots of other frameworks can do this very simply.

I have found Yii2 very difficult to work with when it comes to composite primary and foreign keys. There is almost no way to handle composite foreign keys at all that I have found.

Composite primary and foreign keys are extremely common in even the most simple database models. In my opinion, this oversight drastically limits the abilities of the Yii2 framework and makes it unsuitable for anything other than the simplest of applications.

I have been an active member of the Yii2 community for just over a year now, and have always supported it and tried to help, but I feel like there are some very bad decisions being made. Hopefully this is one that will get resolved eventually.