On 07/08/12 01:40, Lightee wrote:
> I notice that CakePHP does not allow composite primary key. Why is
> this so? Is it because composite primary keys are bad for some reason
> or is it simply to stick to convention? I have been using MS Access
> and there is no such restriction.
> --
> 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+unsubscribe@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/cake-php
Composite primary keys are not 'bad' but they are ALWAYS replaceable. At
the end of the day, a primary key uniquely identifies a record in a
database table and CakePHP relies on this being either an auto
incrementing integer or a 36 character UUID.
The reason Cake does this is simple. Primary key values like this can be
generated automatically and Composite primary keys can't. A composite
key is tailored to your data so Cake cannot possibly work out what the
values should be, you have to do it by hand. If Cake cannot generate
primary key values then the Model code gets broken... what is Cake
supposed to do when you save a record and it needs to generate a new key ?
You could create an AppModel subclass to implement this yourself which
would not be too arduous as you know what the data is, but it is far
easier to make the composite primary key into keys then add another
auto-incrementing key as the primary. All you need to do then is add
code into your Cake generated models to handle your composite keys for
CRUD by implementing the Model callbacks.
I do not know of any PHP frameworks that handle Composite keys very
well, since they ALL require a way of determining which values to put in
them.
Steve.
--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Tuesday, August 7, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment