Changeset 342 for trunk/Model.php
- Timestamp:
- Jan 17, 2012, 10:37:59 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Model.php
r341 r342 16 16 var $Properties; 17 17 18 function __construct( )18 function __construct($Database) 19 19 { 20 $this->Database = &$Database; 20 21 $this->AddPropertyDateTime('TimeCreate'); 21 22 $this->AddPropertyOneToMany('UserCreate', 'User'); … … 67 68 'Column' => $Column); 68 69 } 70 71 function Install() 72 { 73 $Query = 'CREATE TABLE IF NOT EXISTS `'.$this->Name.'` ('. 74 '`Id` int(11) NOT NULL AUTO_INCREMENT,'; 75 foreach($this->Properties as $Property) 76 { 77 if($Property['Type'] == PropertyDateTime) 78 $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,'; 79 else if($Property['Type'] == PropertyString) 80 $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,'; 81 else if($Property['Type'] == PropertyText) 82 $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,'; 83 else if($Property['Type'] == PropertyInteger) 84 $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,'; 85 else if($Property['Type'] == PropertyFloat) 86 $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,'; 87 else if($Property['Type'] == PropertyOneToMany) 88 $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 89 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 90 else if($Property['Type'] == PropertyManyToOne) 91 $Query .= ''; 92 else if($Property['Type'] == PropertyManyToMany) ; 93 // Create many-to-many table 94 //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 95 // 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 96 } 97 $Query .= 'PRIMARY KEY (`Id`)'. 98 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ;'; 99 $this->Database->query($Query); 100 foreach($this->Properties as $Property) 101 { 102 if($Property['Type'] == PropertyOneToMany) 103 $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD CONSTRAINT '. 104 '`'.$this->Name.'_ibfk_'.$Property['Name'].'` FOREIGN KEY (`'.$Property['TargetModel'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);'); 105 } 106 } 107 108 function UnInstall() 109 { 110 foreach($Model->Properties as $Property) 111 { 112 if($Property['Type'] == PropertyManyToMany) 113 ; // Delete many-to-many table 114 } 115 $this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`'); 116 } 69 117 } 70 118
Note:
See TracChangeset
for help on using the changeset viewer.