Development

#4002 (Set a proper empty_value in boolean validator)

You must first sign up to be able to contribute.

Ticket #4002 (closed defect: fixed)

Opened 4 months ago

Last modified 4 months ago

Set a proper empty_value in boolean validator

Reported by: tommyd Assigned to: fabien
Priority: minor Milestone: 1.1.1
Component: validation Version: 1.1.0
Keywords: Cc:
Qualification: Unreviewed

Description

Follow-up patch for #3996: If a boolean field is configured and saved, a non-ticked checkbox is saved as NULL value by propel, because symfony applies NULL as default value for empty boolean values.

The problem here is that propel on the other hand only converts non-null values to boolean values, sample code of a generated BaseObject?:

    public function setFoo($v)
    {
        if ($v !== null) {
            $v = (boolean) $v;
        }

        if ($this->foo !== $v || $v === false) {
            $this->foo = $v;
            $this->modifiedColumns[] = FooPeer::FOO;
        }

        return $this;
    } // setFoo()

Now I don't know if I should blame propel or symfony for this (IMHO its already wrong that the propel guys allow three values for the boolean, i.e. a tri-state type with true, false or null, while people actually expect a boolean to be only a two-state value type) - I still have attached a patch which sets an explicit empty_value as default value for boolean fields in symfony. If there is another way of "overriding" the default behaviour and too many people expect the default value being NULL, then please correct me...

Attachments

boolean_validator.patch (355 bytes) - added by tommyd on 07/15/08 13:53:49.
boolean_validator_with_unit_test.patch (1.1 kB) - added by tommyd on 07/15/08 14:14:44.
as promised, this time with a fixed unit test

Change History

07/15/08 13:53:49 changed by tommyd

  • attachment boolean_validator.patch added.

07/15/08 14:14:44 changed by tommyd

  • attachment boolean_validator_with_unit_test.patch added.

as promised, this time with a fixed unit test

07/16/08 00:12:36 changed by Carl.Vondrick

  • status changed from new to closed.
  • resolution set to fixed.

(In [10306]) 1.2: fixed handling boolean values in radio and checkbox widgets (closes #3825, #3996, #4002)

07/16/08 00:16:29 changed by Carl.Vondrick

  • milestone set to 1.1.1.