Evening all,

Not sure if this is a core bug or if someone can highlight what I am doing 
wrong.

I'm developing a site where after a company places a booking on a course 
they can then review the booking and specify alternative delegates if one 
or more of the original delegates cannot attend.  I can't remember why we 
came up with the idea of keeping a record of the original delegate but we 
have.

The problem is that if you have a booking with two delegates and add an 
alternative for the first delegate but leave the second alternative 
delegate field blank, updateCounterCache() runs on the first alternative 
delegate fine, but then runs again for the second one with a value of NULL 
and somehow updates the previous alternative delegate's count with a count 
of all bookings where alternative_delegate_id = NULL.

Now I can stop this problem occurring with a simple modification to 
the core, but 9.99 times out of 10 it turns out that I am doing something 
daft in my code and the core is just fine as it is.

Here is my change though, line 1917 of /lib/Cake/Model/Model.php change
$this->{$parent}->updateAll(
  array($field => $count),
  array($this->{$parent}->escapeField() => $keys[$foreignKey])
);

to:
if ($keys[$foreignKey]) { // stop updates if foreign key has no value
  $this->{$parent}->updateAll(
  array($field => $count),
  array($this->{$parent}->escapeField() => $keys[$foreignKey])
  );
}

Paul.

-- 
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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to