Changeset 1351
- Timestamp:
- 07/31/09 02:05:18 (1 year ago)
- Files:
-
- trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php (modified) (2 diffs)
- trunk/test/fixtures/app/installers/bb_installer.php (modified) (1 diff)
- trunk/test/fixtures/app/models/bb.php (modified) (1 diff)
- trunk/test/unit/lib/AkActiveRecord/_AkActiveRecord_nested_finders.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php
r1345 r1351 870 870 $available['load_associations'] = false; 871 871 $available['load_acts'] = $load_acts; 872 872 /** 873 * unserializing data 874 */ 875 /**$serialized_attributes = !empty($instance->serialize)? Ak::toArray($instance->serialize):array(); 876 $serialized_attributes = array_intersect(array_keys($available),$serialized_attributes); 877 foreach($serialized_attributes as $serialized_attribute) { 878 if($instance->_shouldSerializeColumn($serialized_attribute)) { 879 $available[$serialized_attribute] = @unserialize($available[$serialized_attribute]); 880 } 881 }*/ 882 $available = $this->_castAttributesFromDatabase($available,$instance); 873 883 $obj=&$parent->$assoc_name->build($available,false); 874 884 … … 884 894 } 885 895 } 886 896 function _castAttributesFromDatabase($attributes = array(),$record = null) 897 { 898 foreach($attributes as $key => $value) { 899 $attributes[$key] = $this->_castAttributeFromDatabase($key,$value,$record); 900 } 901 return $attributes; 902 } 903 function _castAttributeFromDatabase($column_name,$value, $record) 904 { 905 $column_type = $record->getColumnType($column_name); 906 907 if($column_type){ 908 if('integer' == $column_type){ 909 return is_null($value) ? null : (integer)$value; 910 //return is_null($value) ? null : $value; // maybe for bigint we can do this 911 }elseif('boolean' == $column_type){ 912 if (is_null($value)) { 913 return null; 914 } 915 if ($this->_getDatabaseType()=='postgre'){ 916 return $value=='t' ? true : false; 917 } 918 return (integer)$value === 1 ? true : false; 919 }elseif(!empty($value) && 'date' == $column_type && strstr(trim($value),' ')){ 920 return substr($value,0,10) == '0000-00-00' ? null : str_replace(substr($value,strpos($value,' ')), '', $value); 921 }elseif (!empty($value) && 'datetime' == $column_type && substr($value,0,10) == '0000-00-00'){ 922 return null; 923 }elseif ('binary' == $column_type && $this->_getDatabaseType() == 'postgre'){ 924 $value = $this->_db->unescape_blob($value); 925 $value = empty($value) || trim($value) == 'null' ? null : $value; 926 }elseif($record->_shouldSerializeColumn($column_name)){ 927 $this->_ensureClassExistsForSerializedColumnBeforeUnserializing($column_name); 928 $value = @unserialize($value); 929 } 930 } 931 return $value; 932 } 887 933 function getCollectionHandlerName($association_id) 888 934 { trunk/test/fixtures/app/installers/bb_installer.php
r1286 r1351 3 3 class BbInstaller extends AkInstaller 4 4 { 5 function up_2() 6 { 7 $this->addColumn('bbs','languages string(200)'); 8 $this->addColumn('bbs','other string(200)'); 9 } 10 function down_2() 11 { 12 $this->removeColumn('bbs','languages'); 13 $this->removeColumn('bbs','other'); 14 } 5 15 function up_1() 6 16 { trunk/test/fixtures/app/models/bb.php
r1286 r1351 5 5 var $belongsTo = array('aa'); 6 6 var $habtm = array('ccs'); 7 var $serialize = array('languages','other'); 7 8 } 8 9 trunk/test/unit/lib/AkActiveRecord/_AkActiveRecord_nested_finders.php
r1286 r1351 29 29 $aa = &$this->Aa->create(array('name'=>'first aa')); 30 30 $this->assertTrue($aa); 31 $bb1 = &$this->Bb->create(array('name'=>'first bb' ));32 $bb2 = &$this->Bb->create(array('name'=>'second bb' ));31 $bb1 = &$this->Bb->create(array('name'=>'first bb','languages'=>array('es','de'),'other'=>array(1,2,3))); 32 $bb2 = &$this->Bb->create(array('name'=>'second bb','languages'=>array('en','fr'),'other'=>array(4,5,6))); 33 33 $babies = array($bb1,$bb2); 34 34 //Ak::debug($aa->babies); 35 //die; 35 36 //die; 36 37 $aa->babies->set($babies); … … 61 62 $this->assertEqual('second bb',$found_first_aa->bbs[0]->name); 62 63 64 /** 65 * now find them back and test the serialized bb values 66 */ 67 68 $found_first_aa = $this->Aa->findFirstBy('name','first aa',array('include'=>array('bbs'=>array('order' => 'id ASC')))); 69 $this->assertTrue($found_first_aa); 70 $this->assertTrue($found_first_aa->bbs); 71 $this->assertEqual(2,$found_first_aa->babies->count()); 72 $this->assertEqual(array('en','fr'),$found_first_aa->bbs[1]->languages); 73 $this->assertEqual(array(4,5,6),$found_first_aa->bbs[1]->other); 74 $this->assertEqual(array('es','de'),$found_first_aa->bbs[0]->languages); 75 $this->assertEqual(array(1,2,3),$found_first_aa->bbs[0]->other); 63 76 } 64 77 … … 422 435 423 436 } 437 438 424 439 } 425 440
