Changeset 2255
- Timestamp:
- 03/09/2008 11:07:35 PM (10 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/ORM.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/ORM.php
r2218 r2255 77 77 // Preloaded object 78 78 $this->object = $id; 79 80 // Convert the value to the correct type 81 $this->load_object_types(); 79 82 } 80 83 else … … 618 621 } 619 622 623 // Convert the value to the correct type 624 $this->load_object_types(); 625 620 626 // Reset object status 621 627 $this->changed = array(); … … 673 679 // Load the first result, if there is only one result 674 680 $this->object = $result->current(); 681 682 // Convert the value to the correct type 683 $this->load_object_types(); 675 684 } 676 685 else … … 700 709 // Create and return the object 701 710 return ORM::factory(inflector::singular($table)); 711 } 712 713 /** 714 * Converts the loaded object values to correct types. 715 * 716 * @return void 717 */ 718 protected function load_object_types() 719 { 720 foreach (self::$fields[$this->table] as $field => $data) 721 { 722 if (isset($this->object->$field)) 723 { 724 if ( ! empty($data['binary']) AND ! empty($data['exact']) AND $data['length'] == 1) 725 { 726 // Use boolean for an binary(1) field 727 $data['type'] = 'boolean'; 728 } 729 730 switch ($data['type']) 731 { 732 case 'int': 733 $this->object->$field = (int) $this->object->$field; 734 break; 735 case 'float': 736 $this->object->$field = (float) $this->object->$field; 737 break; 738 case 'boolean': 739 $this->object->$field = (bool) $this->object->$field; 740 break; 741 } 742 } 743 } 702 744 } 703 745
