Re: Overriding models / pretending to delete rows
Hi! Thanks for your reply. > Oh, and as a tip, all Cake find functions actually end up using > findAll - including exists, findCount, find, etc. So just change > findAll - you don't have to change each of them separately. Thank you, I'll take out the findCount() overriding bit then! Does it also affect generateList, or do I still need to specify the override for that too? > Also, if all you want to do is set some additional conditions, you > could do this in the AppModel beforeFind() callback - that's what it > is there for (rather than duplicating/changing the findAll > functionality). Really? I had a quick look at that first, but judging by http://api.cakephp.org/1.2/class_model.html#fca41a83b23b6ec2fd91e75b5845a3ec it looks to me as if you can only use beforeFind() to tell Cake to either go ahead with the find or not do it at all. How do you use it to override the conditions? Thank you very much for your help, Zoe. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Overriding models / pretending to delete rows
On Sep 13, 1:34 am, Grant Cox <[EMAIL PROTECTED]> wrote: > Oh, and as a tip, all Cake find functions actually end up using > findAll - including exists, findCount, find, etc. So just change > findAll - you don't have to change each of them separately. Or look at the softDelete behavior on the bakery. either use it as it is, or take hints from the code and put that in your app model. hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Overriding models / pretending to delete rows
Oh, and as a tip, all Cake find functions actually end up using findAll - including exists, findCount, find, etc. So just change findAll - you don't have to change each of them separately. Also, if all you want to do is set some additional conditions, you could do this in the AppModel beforeFind() callback - that's what it is there for (rather than duplicating/changing the findAll functionality). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Overriding models / pretending to delete rows
Simple solution is to add 'deleted => 0' to your association. var $hasMany = array( 'Album' => array( 'className' => 'Album', 'conditions' => 'Album.deleted = 0', ), ); In one app I have a much more complex solution of a model behaviour that dynamically modifies all queries, but to tell you the truth it is overkill :P --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Overriding models / pretending to delete rows
Hi. I'm trying to override CakePHP's deleting of rows in the database so it only looks like it's deleting them. So far I've done the following: * Updated all the tables except cake_sessions to include the column `deleted` tinyint(1) unsigned NOT NULL default '0' * Created the file app/app_model.php and entered the following (I hope this may be useful to anyone else trying to do the same thing later on, this is pretty generic code): name}.deleted = FALSE"; } elseif (is_null($conditions)) { $conditions = "{$this->name}.deleted = FALSE"; } return parent::findAll($conditions, $fields, $order, $limit, $page, $recursive); } function findCount($conditions = NULL) { if (is_array($conditions)) { $not_deleted = array(); $conditions = $conditions + $not_deleted; } elseif (is_string($conditions)) { $conditions .= " AND {$this->name}.deleted = FALSE"; } elseif (is_null($conditions)) { $conditions = "{$this->name}.deleted = FALSE"; } return parent::findCount($conditions); } function generateList($conditions = NULL, $order = NULL, $limit = NULL, $keyPath = NULL, $valuePath = NULL, $groupPath = NULL) { if (is_array($conditions)) { $not_deleted = array(); $conditions = $conditions + $not_deleted; } elseif (is_string($conditions)) { $conditions .= " AND {$this->name}.deleted = FALSE"; } elseif (is_null($conditions)) { $conditions = "{$this->name}.deleted = FALSE"; } return parent::generateList($conditions, $order, $limit, $keyPath, $valuePath, $groupPath); } // Only pretend to delete data function del($id) { $this->create(); $this->read(NULL, $id); $this->saveField('deleted', TRUE); } } ?> * Updated all the app/model/*.php files so that the links to other tables all contain in the array key 'Conditions' and the array value '[Table name].deleted = FALSE' All of this works fine for pages that list single models, but for the recersive ones, it's still getting rows that are linked to other rows that in turn have been deleted. For example, if I was bringing up a list of albums and which genre they belonged to, it would be avoiding any deleted albums (good), but showing all albums which belong to a deleted genre (not so good). Am I overlooking something, or is this just correct behaviour on the assumption that secondary information should always be pulled in? I can update all the findAll, findCount and generateList lines to work around this, but if it turned out I was missing something simple, it'd be nice to fix it in the model area instead of the controller one. Thanks for your help everyone, and I hope my example code helps anyone else trying to only pretend to delete data. Zoe. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---