Ticket #113 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Akelos changes to empty any integer values of zero when saving records

Reported by: asejua Assigned to: Kaste
Priority: critical Milestone: 0.9
Component: Active Record Keywords: value casting ActiveRecord


When editing or adding a record with integer fields, if placed a zero (0) on this ones Akelos changes it to an empty value before saving the record, causing the value saved is the default defined in the table design when inserting or leaving the previous value of the field when updating. That should be changed, guess it's a critical priority.

Example: An object edit form appears and has a field that has a integer value that other script has filled in previously, let's say 635. Editing the field placing a cero 0 on it and saving causes the field still keeps the 635 value. Changing it to a > 0 value the edit works right, for example placing a 1 on the field.

I've debugged the process that saves the edited register and I've found that the function is "cleaning" the field value is castAttributeForDatabase (AkActiveRecord?.php line 3256), more precisely in this function's last line:

return empty($this->_columns[$column_name]['notNull']) ? ($result === ? "" : $result) : ($result == 'null' ? : $result);

When arrives to this point the last $result == 'null' ? comparison returns true (when $result in that moment is (int)0. So, the function returns an empty value. When updating, all the other fields are saved okay, but the emptied ones are obviously ignored, leaving the old values instead.

Change History

01/19/08 11:54:18 changed by Kaste

  • keywords changed from integer empty save records to value casting ActiveRecord.
  • owner set to Kaste.
  • status changed from new to assigned.

simplest test that fails. (constraint: column must be defined with NOT NULL.

    function test_set_Integer_Column_To_Zero_When_Column_Defined_As_Not_Null__ticket_113()
        $this->installAndIncludeModels(array('Product'=>'id,products_status int not null'));
        $prod = new Product(array('products_status' => 2));
        $this->assertTrue($prod->updateAttribute( 'products_status', 0 ));
        $this->assertTrue($prod->products_status == 0,'Setting to 0 failed. products_status is '.$prod->products_status);
        $this->assertTrue($prod->products_status == 0,'Save failed. products_status is '.$prod->products_status);

01/19/08 13:39:06 changed by Kaste

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

04/04/08 12:39:45 changed by Kaste

Was fixed in [466]