root

Changeset 731

Show
Ignore:
Timestamp:
11/14/09 09:43:26 (4 months ago)
Author:
wbond
Message:

Fixed ticket #345 - fActiveRecord::changed() now properly compares NULL and blank strings

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fActiveRecord.php

    r730 r731 Hide Line Numbers
    1616 * @link       http://flourishlib.com/fActiveRecord 
    1717 *  
    18  * @version    1.0.0b50 
     18 * @version    1.0.0b51 
     19 * @changes    1.0.0b51  Made ::changed() properly recognize that a blank string and NULL are equivalent due to the way that ::set() casts values [wb, 2009-11-14] 
    1920 * @changes    1.0.0b50  Fixed a bug with trying to load by a multi-column primary key where one of the columns was not specified [wb, 2009-11-13] 
    2021 * @changes    1.0.0b49  Fixed a bug affecting where conditions with columns that are not null but have a default value [wb, 2009-11-03] 
     
    172173        } 
    173174         
     175        $oldest_value = $old_values[$column][0]; 
     176        $new_value    = $values[$column]; 
     177         
    174178        // We do a strict comparison when one of the values is NULL since 
    175         // NULL is almost always meant to be distinct from 0, FALSE, etc 
    176         if ($old_values[$column][0] === NULL || $values[$column] === NULL) { 
    177             return $old_values[$column][0] !== $values[$column];     
    178         } 
    179          
    180         return $old_values[$column][0] != $values[$column];  
     179        // NULL is almost always meant to be distinct from 0, FALSE, etc. 
     180        // However, since we cast blank strings to NULL in ::set() but a blank 
     181        // string could come out of the database, we consider them to be 
     182        // equivalent, so we don't do a strict comparison 
     183        if (($oldest_value === NULL && $new_value !== '') || ($new_value === NULL && $oldest_value !== '')) { 
     184            return $oldest_value !== $new_value;     
     185        } 
     186         
     187        return $oldest_value != $new_value;  
    181188    } 
    182189