It seems to me (cake 1.2) that the save call will perform again the
validation. Maybe use a validation with a 'rule' => 'checkUnique' (to
write in your model). Then the save will call this validation and fail
if the code already exist.

On Aug 24, 1:49 am, rtanz <[EMAIL PROTECTED]> wrote:
> hi i have the following which my logic tells me should not save if a
> module with the same code is already saved in the database. Now when i
> test it i can see that it is finding a matching code and entering into
> the  if ($this->Module->find($conditions) statement, and i assume
> therefore invalidating the code field. However it saves while as i was
> reading in the manual it is not supposed to save after i set the
> invalidate. so anyone knows what i might be doing wrong here? thanks
>
> function admin_add() {
>         if (empty($this->data)) {
>             $this->render();
>         } else {
>             $this->cleanUpFields();
>             $module = $this->data['Module']['code'];
>             $conditions = array("Module.code"=>"$module");
>             if ($this->Module->find($conditions)) {
>                 $this->Module->invalidate('code');
>             }
>             if ($this->Module->save($this->data)) {
>                 $this->admin_createReview($this->Module->getLastInsertId(), 
> $this->data['Module']['code'],$this->data['Module']
>
> ['name'],$this->data['Module']['year_delivered']);
>                 $this->Session->setFlash('The Module has been saved
> and an associated review created');
>                 $this->redirect('/admin/modules/index');
>             } else {
>                 $this->Session->setFlash('Please correct errors
> below.');
>             }
>         }
>     }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to