tags:

views:

55

answers:

1

I'm using counterCache to track the number of chapters that have been posted to their related stories.

This all works fine, apart from the fact that when the chapter_count field in the database gets updated, the modified field for that record does not.

Is there any way that I can set Cake to automatically update the modified field when the counterCache functionality runs?

Thank you.

+2  A: 

I assume you have a modified field in the chapters table? Cakes default behaviour is to update it for that specific record.

You could add a count_modified column to the table, and then in your models beforeSave() you could assign the current timestamp to that and then save it.

Something like perhaps,

function beforeSave(){
  $this->data['Chapter']['count_modified'] = date();
}

Which should then save that column every time the model performs a save action. Here's the method, http://api.cakephp.org/class/model#method-ModelbeforeSave and a book link, http://book.cakephp.org/view/683/beforeSave

DavidYell