Re: Model::saveField emptying my data array
Edit: Calling model-save in my behaviour caused my HABTM tags to be saved twice duplicating tags for each blog entry. so I switched $model-data = $model-save($model-data, array('validate' = false, 'callbacks' = false)); to $model-updateAll(array($field=$count), array($model-alias.'_id'= $model-id)); And all appears to be fine, by HABTM relationship updates two counts, my tags are saved as expected and phpThumb automatically creates a thumbnail from the first image in the TinyMCE controlled body of my post. And breath 1-2-3 Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Model::saveField emptying my data array
Hi, My experience with behaviours goes as far as using the core ones or those kindly made available by the community. One of those that I use is counter_cache_habtm http://bakery.cakephp.org/articles/view/counter-cache-behavior-for-habtm-relations Within the behaviour's afterSave method it checks to see if the model's database includes a count field and if so fetches the updated count and saves it with the following command: $model-saveField($field, $count, array('validate' = false, 'callbacks' = false)); My problem is that after the above command runs it clears $model- data, which I need for my afterSave method in the controller. How do I update the count field without blanking my data array? Thanks, Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Model::saveField emptying my data array
Think I resolved it, but happy for someone to confirm if this is a good solution. When searching for issues surrounding Model::save blanking the data array I came across a blog post on debuggable from 2007: http://debuggable.com/posts/modelsave-now-returns-an-array:480f4dd6-0a7c-4026-ad5a-49c8cbdd56cb Armed with the fact that I now knew Model::save returns Model-data I changed the save function to the following: $count = $joinModel-find('count', array( 'fields'=$assocData['associationForeignKey'], 'conditions'=array($assocData['foreignKey'] = $model-id) )); $model-set($field, $count); $model-data = $model-save($model-data, array('validate' = false, 'callbacks' = false)); By changing saveField() to save() and adding $model-data = in front of the save call I retain my data array. Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.