Hi Krissy, Thanks for that tip - once I've solved my problem I'll definitely improve the solution with your tip in mind!
Adam. On Feb 24, 8:11 pm, "Krissy Masters" <[email protected]> wrote: > Not so much related to your post but I noticed something so tip for you: > > I do the same thing delete an ordered item 1,2,3,4,5,6 delete #4 so I grab > the Model.order I am deleting and updateAll where Model.order is greater > than 4 for this example saving un-necessary save's 1,2,3 never changed so > why resave them :) Not a big deal but imagine hundreds of users re-ordering > stuff constantly with hundreds of records being re-ordered. Save the db the > trouble. > > $this->$currentModel->updateAll(array( > $currentModel.'.order' => $currentModel.'.order-1'), array( > $currentModel.'.user_id' => $this->owner_id, > $currentModel.'.order >' => $record[$currentModel]['order'] > )); > > K > > > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On Behalf > > Of adam_g2000 > Sent: Thursday, February 24, 2011 12:07 AM > To: CakePHP > Subject: afterDelete not running as intended > > Hi Guys, > > I have this method I've written... > > function tidyup() { > //Re-sort orders to remove the 'hole' > // Create an array of the image table contents of IDs and Orders. > $conditions = array( > 'fields' => array('id','order'), > 'order' => 'Image.order ASC' > ); > $images = $this->Image->find('all', $conditions); > //Loop through looking for order/count disparity and tidying up when > disparity is found. > $counter = 1; > foreach ($images as $image): > if ($image['Image']['order'] != $counter) { > $image['Image']['order'] = $counter; > $this->Image->save($image, false, > array('id','order')); > } > $counter++; > endforeach; > $this->redirect(array('action' => 'index')); > } > > ...to reorder a list of Images in a database table once one is > deleted. This works perfectly. > > However, what I really want to do is have it triggered automatically > once an Image is deleted. > > So I would expect just changing function tidyup to function > afterDelete should work perfectly. When I do that, the function never > runs. > > Can I get a sanity check please? Can anyone spot my error? > > Thanks in advance for any offers of assistance. > > -- > Our newest site for the community: CakePHP Video > Tutorialshttp://tv.cakephp.org > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > others with their CakePHP related questions. > > To unsubscribe from this group, send email to > [email protected] For more options, visit this group > athttp://groups.google.com/group/cake-php -- 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
