Changeset 295

Show
Ignore:
Timestamp:
07/28/07 20:44:07 (1 year ago)
Author:
bermiferrer
Message:

Integer fields in Active Record models can be set now as string (including '0'). Fixes #21

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/boot.php

    r290 r295  
    126126 
    127127    defined('AK_PROTOCOL') ? null : define('AK_PROTOCOL',isset($_SERVER['HTTPS']) ? 'https://' : 'http://'); 
    128     defined('AK_HOST') ? null : define('AK_HOST', $_SERVER['SERVER_NAME'] == 'localhost' ? $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_NAME']); 
     128    defined('AK_HOST') ? null : define('AK_HOST', $_SERVER['SERVER_NAME'] == 'localhost' ?  
     129    // Will force to IP4 for localhost until IP6 is supported by helpers 
     130    ($_SERVER['SERVER_ADDR'] == '::1' ? '127.0.0.1' : $_SERVER['SERVER_ADDR']) :  
     131    $_SERVER['SERVER_NAME']); 
    129132    defined('AK_REMOTE_IP') ? null : define('AK_REMOTE_IP',(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']); 
    130133 
  • trunk/lib/AkActiveRecord.php

    r289 r295  
    32623262            case 'serial': 
    32633263            case 'integer': 
     3264                $value = is_null($value) ? null : (integer)$value; 
    32643265            case 'float': 
    3265             $result = (empty($value) && @$value !== 0) ? 'null' : (is_numeric($value) ? $value : $this->_db->qstr($value)); 
     3266            $result = (empty($value) && $value !== 0) ? 'null' : (is_numeric($value) ? $value : $this->_db->qstr($value)); 
    32663267            $result = !empty($this->_columns[$column_name]['notNull']) && $result == 'null' && $this->_getDatabaseType() == 'sqlite' ? '0' : $result; 
    32673268            break; 
     
    32803281            $column_type = $this->getColumnType($column_name); 
    32813282            if($column_type){ 
    3282                 if(!empty($value) && 'date' == $column_type && strstr(trim($value),' ')){ 
     3283                if('integer' == $column_type){ 
     3284                    return is_null($value) ? null : (integer)$value; 
     3285                }elseif('boolean' == $column_type){ 
     3286                    return (integer)$value === 1 ? true : false; 
     3287                }elseif(!empty($value) && 'date' == $column_type && strstr(trim($value),' ')){ 
    32833288                    return substr($value,0,10) == '0000-00-00' ? null : str_replace(substr($value,strpos($value,' ')), '', $value); 
    32843289                }elseif (!empty($value) && 'datetime' == $column_type && substr($value,0,10) == '0000-00-00'){ 
     
    32863291                }elseif ('binary' == $column_type && $this->_getDatabaseType() == 'postgre'){ 
    32873292                    return $this->_db->BlobDecode($value); 
    3288                 }elseif('boolean' == $column_type){ 
    3289                     return (integer)$value === 1 ? true : false; 
    32903293                } 
    32913294            } 
  • trunk/test/fixtures/app/installers/picture_installer.php

    r2 r295  
    77        $this->createTable('pictures', ' 
    88        id integer max=10 auto increment primary, 
    9         property_id integer
     9        property_id
    1010        title string limit=200' 
    1111        ); 
  • trunk/test/fixtures/app/installers/tag_installer.php

    r55 r295  
    77        $this->createTable('tags', ' 
    88        id integer max=10 auto increment primary, 
     9        score int default 100, 
    910        name string 50' 
    1011        ); 
  • trunk/test/unit/lib/AkActiveRecord/AkBelongsTo.php

    r217 r295  
    7777        $this->assertFalse($Picture->main_thumbnail->isNewRecord()); 
    7878 
    79         $CeBitPic = $Picture->findFirstBy('title:has','CeBIT', array('include'=>'main_thumbnail')); 
     79        $CeBitPic =& $Picture->findFirstBy('title:has','CeBIT', array('include'=>'main_thumbnail')); 
    8080 
    8181        $this->assertEqual($CeBitPic->title, 'The Akelos Media Team at CeBIT'); 
     
    162162        $this->assertEqual($Thumbnail->picture->getType(), 'belongsTo'); 
    163163 
    164         $Thumbnail = $Thumbnail->findFirstBy('caption:has','Lucky'); 
    165  
    166         // Its necesary to call loadAssociations after a finder in order to keep reference integrity 
    167         $Thumbnail->loadAssociations(); 
    168  
    169         $this->assertReference($Thumbnail->belongsTo->load('picture'), $Thumbnail->picture); 
     164        $Thumbnail =& $Thumbnail->findFirstBy('caption:has','Lucky', array('include'=>'picture')); 
    170165 
    171166        $this->assertEqual($Thumbnail->picture->getType(), 'Picture');