#6494: saveAll ignores filtering in beforeSave method -------------------------------------------+-------------------------------- Reporter: digitalspaghetti | Type: Bug Status: new | Priority: Medium Milestone: 1.2.x.x | Component: Model Version: 1.2 Final | Severity: Normal Keywords: model, beforeSave, saveAll | Php_version: PHP 5 Cake_version: | -------------------------------------------+-------------------------------- In my app I have two models, a Question and Answer model. On the question form, there is a section to add X number of answers (currently set to 5), however the user only has to enter UPTO this value - they can quite happily enter only 2 or 3 answers.
I used the same code below in my Question beforeSave method when calling saveAll in the controller to filter out empty examples, however all 5 still saved, even though the answers were empty. This created empty entries in the database, even though the answer_text field was set to NOT NULL. Moving it to the controller and using before the $this->Question->saveAll() method did fix this, but I expected that the beforeSave would do the same thing. {{{ function beforeSave() { foreach ($this->data['Answer'] as $key => $val) { if ($val['answer_text'] == "") { $this->data['Answer'] = Set::remove($this->data['Answer'], $key); } } // Using print_r, I confirmed that the empty answer fields HAVE been removed, however they still seem to get saved. For example if I only have two answers, I only have an array of two values in the $this->data['Answer']. return true; } }}} -- Ticket URL: <https://trac.cakephp.org/ticket/6494> 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 tickets-cakephp@googlegroups.com To unsubscribe from this group, send email to tickets-cakephp+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/tickets-cakephp?hl=en -~----------~----~----~----~------~----~------~--~---