#5878: counterCache updates count for models with no parent defined (null 
allowed)
----------------------------------------+-----------------------------------
    Reporter:  BrendonKoz               |          Type:  Bug   
      Status:  new                      |      Priority:  Medium
   Milestone:  1.2.x.x                  |     Component:  Model 
     Version:  RC3                      |      Severity:  Normal
    Keywords:  countercache model null  |   Php_version:  n/a   
Cake_version:  1.2.0.7692 RC3           |  
----------------------------------------+-----------------------------------
 Although this is specific to RC3, I have tested it with a nightly build as
 of December 11, 2008.  The file version of model.php (from this nightly)
 was 7893, and the issue still exists.
 [[BR]]
 [[BR]]

 == Description of Problem ==
 I had the need to have a single table in the database also create
 instances that were related in some way to another in the same table.  I
 also needed to count how many times (if any) those original instances had
 created "children" instances.  A clean bake of a self-joined model --
 (hasMany, belongsTo) (SQL attached), controller, and standard CRUD view
 files -- only requires a few modifications to notice this behavior.  By
 adding the following code to the belongsTo variable in the model:

 {{{ 'counterCache' => 'child_count' }}}

 ...and changing the FormHelper's default render for the parent_id in the
 add view, the problem will show itself on the add action.

 {{{ echo $form->input('parent_id', array('empty'=>true)); }}}

 The problem is that in this specific case, not all instances will have a
 parent.  The unit tests method, "testCounterCacheWithSelfJoin" in
 model.test.php, uses one model record with no parent (the parent ID is set
 to 0 in the "category_thread_fixture.php" file), all the rest have a
 parent.  What it appears counterCache is doing is counting all (current as
 of the insert) records with a parent_id of NULL (or 0, or ""), and using
 that COUNT value to update the child count.
 [[BR]]
 [[BR]]
 As of now, this means that counterCache cannot properly be used by self-
 joined models that do not *require* a parent_id for all records.  (This
 may also apply to all models with the same requirements.)[[BR]]
 [[BR]]
 I have attempted to create multiple test cases for this, all without
 success.  I believe my understanding of the testing framework is to blame,
 but after calling updateCounterCache from the unit tests, the same action
 is '''not''' performed as when using the full app.  The simple SQL/bake
 operation can show the issue at hand, however.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5878>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

  • [CakePHP : The Rapid Dev... CakePHP : The Rapid Development Framework for PHP

Reply via email to