Re: Composite Primary Keys
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 jeremybu...@classoutfit.com 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 > cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Composite Primary Keys
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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Composite Primary Keys
>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? Thanks! -- 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Composite Primary Keys
I work in a company with a legacy database designed using relations with composite primary keys and change the database is not an option... Cake does not support an array of keys by default to set model`s $primaryKey. Is there any plugin or update in sight?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Composite Primary Keys
On 11/9/07, Mr-Yellow <[EMAIL PROTECTED]> wrote: > Nice to know I just spent months designing a massive properly > normalised and indexed database. > Only to findout Cake doesn't support properly designed databases. After designing the theoretical correct model, I always thought there was an additional step "apply any optimizations for the technical implementation". Adding a surrogate primary key to each table belongs to that category, if you want to use Cake. I guess your design needs that little bit of extra Cake-tweaking. Regards, Martin -- Martin Schapendonk, [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
RE: Composite Primary Keys
Ben From an academic standpoint [and yes best practice DB design] the us of composite FKs to create a PK is common. Many of my designs in the past used that idea, but with the introduction of so many QaD [Quick and Dirty] methods [aka Rapid Application Development] sometimes the best practices get left behind to form less than perfect solutions that *may be* more efficient when it comes to application development in short time. I know I'd prefer to refer to a composite/joint key such as [book_id, author_id] in a one-many-one table situation as then I know JOINS will result faster as the PK is always indexed. I am sure that cakePHP has some way to get around this hiccup... what I am not sure... Ady --- Adrian Gould Lecturer in IT / Network Engineering / Multimedia Business Finance & Computing [Midland Campus] Swan TAFE PO BOX 1336, Midland WA 6936 Phone: (08) 9267 eMail: [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Composite Primary Keys
Oh just to let you know. Yes I do know what a Unique Index is. We don't really need fanboys to come yell at us that it's 2007. The year doesn't change the fact that doing stuff on the DB engine is safer then in your software. Validation is still very important, but a properly setup database is better. Instead some intelligent discussion that isn't closed off by mods would be nice. Oh as for the comment that it breaks REST. You'd just specify both IDs as you should always, using some surrogate key just introduces the chance for bugs, while meaning any database migration in future could be jeopardised. Flame away. -Ben On Nov 9, 4:31 pm, Mr-Yellow <[EMAIL PROTECTED]> wrote: > YaY!!! > > Nice to know I just spent months designing a massive properly > normalised and indexed database. > Only to findout Cake doesn't support properly designed databases. > > Lock this thread too, just to make sure discussion of their benefit is > quashed and discovery of the feature hole is less obvious. Makes it > easy when this point isn't very well documented and it's so far from > the norm. > > -Ben --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Composite Primary Keys
YaY!!! Nice to know I just spent months designing a massive properly normalised and indexed database. Only to findout Cake doesn't support properly designed databases. Lock this thread too, just to make sure discussion of their benefit is quashed and discovery of the feature hole is less obvious. Makes it easy when this point isn't very well documented and it's so far from the norm. -Ben --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---