Tuesday, June 4, 2013

counterCache - CakePHP 2.0

#### What I did


Added a cacheCounter onto a $belongsTo relationship where the DB will accept NULL for the foreign_key

For Example: Addresses haveMany Users, but a users does not have to have an address.

#### What happened

When I went to delete the User I got the following error:

UPDATE [addresses] SET [user_count] = 0 WHERE [id] IS N''

It is trying to update the cacheCounter when the relationship does not exist.


#### What I expected to happen

When I create the User ($this->User->save) with an address_id of NULL, or even edit the User ($this->User->save) I do not get the error??

Is there something I can put into the counterScope to stop this from happening??

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: