On Mar 17, 2011, at 17:23, hill180 wrote: > From what I have read, I know that Cakephp does not support composite primary > keys. And later the posts go into tags, but I need a push in the right > directions. > > I have Tickets 1-100 that go out for each day. > > The user buys a ticket for a day and the system will process the payment and > return the ticket #. So the ticket# + Day = Primary Key. > > How would I accomplish this with CakePHP, or at least prevent duplicates?
As you said, CakePHP does not support composite primary keys, so don't attempt to use one. Make your primary key a normal autoincrement integer. For your particular requirements of ticket numbering, I suggest you make two additional database fields: ticket number, and day. Define a unique index that spans both of those fields; that'll ensure the combination of ticket number and day will be unique. In your CakePHP app, you'll write code to fill in both fields when creating a new ticket. The day field can presumably be calculated from the current date, and the ticket number can probably be computed by retrieving the maximum ticket number for this day and adding one -- but be sure to watch out for race conditions. (The unique index spanning the two columns will ensure no duplicate entries can be inserted into the database, but if two users try to buy a ticket at the same time, if not coded carefully, it's possible one user's database insert might fail for attempting to insert a duplicate value.) -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
