Unfortunately, cakephp doesn't support compound primary keys. You will need to declare a primary key in cake in order for the save and insert to work properly. A work around is to add an auto_increment field to every table, which implies that the compound key must be removed since Mysql only allows auto_increment to be the ONLY primary key.
But as I'm writing this response, I just thought of something else that I actually have never tried, but just tested and it works! You can get around the issue of having only one primary key by using compound unique keys like so: | cake | CREATE TABLE `cake` ( `id` int(11) NOT NULL auto_increment, `some_id` int(11) NOT NULL default '0', `other_id` int(11) NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `some_id` (`some_id`,`other_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> insert into cake values (null, 1,1); Query OK, 1 row affected (0.00 sec) mysql> insert into cake values (null, 1,2); Query OK, 1 row affected (0.00 sec) mysql> insert into cake values (null, 1,1); ERROR 1062: Duplicate entry '1-1' for key 2 mysql> The duplicate error is good! It means you can really have to primary keys sort to speak! mysql> select * from cake; +----+---------+----------+ | id | some_id | other_id | +----+---------+----------+ | 1 | 1 | 1 | | 2 | 1 | 2 | +----+---------+----------+ 2 rows in set (0.00 sec) Gil On 10/24/06, Erich C. Beyrent <[EMAIL PROTECTED]> wrote: > > > Defining your schema and having the database engine enforce key > > integrity has its advantages and disadvantages. You'll probably want > > to continue to learn about the issues regarding telling mySQL about > > foreign keys. > > What about us poor schmucks who are trying to develop applications using > Cake against an existing database? Because of the amount of existing code > that uses this database, I can't go around changing the schema to conform to > Cake's expectations, and the problem I am having is that many of the built > in functions don't work. > > Is there some way to do schema mapping, or is this a case where I'll need to > define my own custom queries for each model? > > -Erich- > > > > > -- [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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~----------~----~----~----~------~----~------~--~---
