Apologies as I'm new to cake, as well as MVC.

I have a table with a field called "obtained_date", where null is
allowed.

I have the edit action in the controller which was created by bake:

        function edit($id = null) {
                if (empty($this->data)) {
                        if (!$id) {
                                $this->Session->setFlash('Invalid id for 
Skater');
                                $this->redirect('/skaters/index');
                        }
                        $this->data = $this->Skater->read(null, $id);
                        $this->set('franchises', 
$this->Skater->Franchise->generateList());
                } else {
                        $this->cleanUpFields();
                        if ($this->Skater->save($this->data)) {
                                $this->Session->setFlash('The Skater has been 
saved');
                                $this->redirect('/skaters/index');
                        } else {
                                $this->Session->setFlash('Please correct errors 
below.');
                                $this->set('franchises', 
$this->Skater->Franchise-
>generateList());
                        }
                }
        }

In the model for Skater, I have specified a beforeSave() function as:

        function beforeSave()
        {
                // when no obtained_date is set, ensure that the string is 
empty.
                // without this, it would fail with 1292: Incorrect date value: 
'--'
                if (empty($this->data['Skater']['obtained_date']))
                {
                        unset($this->data['Skater']['obtained_date']);
                }

                return true;
        }

Yet, I still receive a sql error when the form I'm submitting doesn't
specify an obtained date.  The error is:

SQL Error: 1292: Incorrect date value: '--' for column 'obtained_date'
at row 1.

Can someone help me understand what else I have to do to clean the
data and ensure that I can persist a null value?

Thank you in advance.

--~--~---------~--~----~------------~-------~--~----~
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