cakephp logo

HABTM error 512 duplicate sql in CakePHP 1.2

While trying to submit a $hasAndBelongsToMany (HABTM) related form under cakephp (1.2 rev 6311) I would get the following SQL Error :-

  • Warning (512): SQL Error: 1062: Duplicate entry '4-1' for key 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 440]

The solution for this was to add the following line to the beginning of the foreach in the cake/libs/model/model.php (between lines 1284/1285) :-

Show Plain Text
PHP code
  1. $newValues = array();

You could also download either the latest CVS or nightly build which has this and other fixes already implemented.

Related Article:
Filed under: Cakephp  Tags: Habtm

0 Responses to “HABTM error 512 duplicate sql in CakePHP 1.2”

Sorry, comments have been closed for this post.
(default) 11 queries took 70 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17175
2DESCRIBE `comments`11112
3DESCRIBE `tags`2212
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`2211
6DESCRIBE `categories_posts`223
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'habtm-error-512-duplicate-sql-in-cakephp-1-2' LIMIT 11111
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (6) 001
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 6 AND `PostsTag`.`tag_id` = `Tag`.`id`) 110
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 6 AND `CategoriesPost`.`category_id` = `Category`.`id`) 1113
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 6111