You beat me to it. If race conditions are are a real possibility, with such low numbers of rows (100) you could even pre-populate the rows before each day starts and then simply allocate them to users throughout the day until they are all used up (assuming 100 is the max, which is what I assume from the question). Then as you prepare tomorrow's tickets, remove unused tickets from yesterday. A bit mad, but possibly part of your solution.
Jeremy Burns Class Outfit [email protected] http://www.classoutfit.com On 17 Mar 2011, at 23:40, Ryan Schmidt wrote: > > 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 -- 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
