Yii Framework Forum: support of composite key by yii CRUD - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

support of composite key by yii CRUD Rate Topic: -----

#1 User is offline   rama 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 18-February 11
  • Location:india

Posted 12 March 2011 - 12:53 AM

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
0

#2 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 12 March 2011 - 01:44 AM

View Postrama, on 12 March 2011 - 12:53 AM, said:

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...
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#3 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 12 March 2011 - 07:37 PM

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.
0

#4 User is offline   rama 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 18-February 11
  • Location:india

Posted 16 March 2011 - 03:33 AM

View Postsensorario, on 12 March 2011 - 07:37 PM, said:

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.
0

#5 User is offline   Pat M 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 12-July 12

Posted 12 July 2012 - 03:16 PM

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.
0

#6 User is offline   leeii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 25-August 13

Posted 01 September 2013 - 03:56 AM

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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users