<h1>roryy</h1>

Cakephp Multiple HABTM bug

Author: roryy, on 14/4/08
Tags: cakephp, HABTM, bug,
Hi do you have problems with your cake model with multiple HABTM fields in cakephp 1.2? It can be the bug in cakephp. Here's the solution.
$this->data:
[Foo] => Array
(
[Foo] => Array
(
[0] => 2
)

)

[Bar] => Array
(
[Bar] => Array
(
[0] => 2
[1] => 3
)

)

This doesn't work without the fix. When you save this cake will add the [foo] to the [bar] table. To fix this you have to edit model.php in /cake/libs/model. Scroll down to function __saveMulti and then look for this line:
  1. foreach ($value as $update) {
and add this line before it:
  1. $newValues = array();

The problem is fixed! Good luck. (This is tested in cakephp 1.2 rev 6311)
Add Comment
Your IP address: 38.107.191.112

© Copyright 2008 - roryydotcom

FlatFish Internet Solutions

CakePHP: the rapid development php framework