Ticket #3473: propel-inheritance.patch
| File propel-inheritance.patch, 6.0 kB (added by Kris.Wallsmith, 8 months ago) |
|---|
-
lib/plugins/sfPropelPlugin/test/unit/sfPropelDatabaseSchemaTest.php
old new 47 47 require_once(dirname(__FILE__).'/../../../../util/sfToolkit.class.php'); 48 48 require_once(dirname(__FILE__).'/../../../../yaml/sfYaml.class.php'); 49 49 50 $t = new my_lime_test(2 61, new lime_output_color());50 $t = new my_lime_test(277, new lime_output_color()); 51 51 52 52 $t->diag('Classical YAML to XML conversion'); 53 53 $p = new sfPropelDatabaseSchema(); -
lib/plugins/sfPropelPlugin/test/unit/fixtures/schema.xml
old new 4 4 <table name="ab_group" phpName="Group" package="foo.bar.lib.model" isI18N="true" i18nTable="ab_group_i18n"> 5 5 <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> 6 6 <column name="name" type="varchar" size="50" /> 7 <column name="type" type="varchar" size="50" inheritance="single"> 8 <inheritance extends="foo.bar.lib.model.Group" key="tight" class="Group_Tight" /> 9 <inheritance extends="foo.bar.lib.model.Group" key="loose" class="Group_Loose" /> 10 </column> 7 11 </table> 8 12 9 13 <table name="cd_user" phpName="User" isI18N="true" i18nTable="cd_user_i18n"> -
lib/plugins/sfPropelPlugin/test/unit/fixtures/schema.yml
old new 4 4 _attributes: { phpName: Group, package: foo.bar.lib.model } 5 5 id: 6 6 name: varchar(50) 7 type: varchar(50) 8 _inheritance: 9 column: type 10 classes: 11 tight: Group_Tight 12 loose: Group_Loose 7 13 8 14 cd_user: 9 15 _attributes: { phpName: User, isI18N: true, i18nTable: cd_user_i18n } -
lib/plugins/sfPropelPlugin/test/unit/fixtures/new_schema.yml
old new 10 10 columns: 11 11 id: 12 12 name: varchar(50) 13 type: varchar(50) 14 inheritance: 15 column: type 16 classes: 17 tight: Group_Tight 18 loose: Group_Loose 13 19 14 20 User: 15 21 tableName: cd_user -
lib/plugins/sfPropelPlugin/lib/propel/sfPropelDatabaseSchema.class.php
old new 116 116 case '_behaviors': 117 117 $classes[$phpName]['behaviors'] = $column_params; 118 118 break; 119 case '_inheritance': 120 $classes[$phpName]['inheritance'] = $column_params; 121 break; 119 122 case '_foreignKeys': 120 123 $classes[$phpName]['foreignKeys'] = $column_params; 121 124 break; … … 191 194 unset($classParams['behaviors']); 192 195 } 193 196 197 // Inheritance 198 if (isset($classParams['inheritance'])) 199 { 200 $tableParams['_inheritance'] = $classParams['inheritance']; 201 unset($classParams['inheritance']); 202 } 203 194 204 // Table attributes 195 205 $tableAttributes = array(); 196 206 if (isset($classParams['tableName'])) … … 247 257 // columns 248 258 foreach ($this->getChildren($table) as $col_name => $column) 249 259 { 260 // inheritance 261 if (isset($table['_inheritance']) && 262 isset($table['_inheritance']['column']) && 263 $col_name == $table['_inheritance']['column'] && 264 isset($table['_inheritance']['classes']) && 265 is_array($table['_inheritance']['classes'])) 266 { 267 $column['inheritance'] = $table['_inheritance']['classes']; 268 unset($table['_inheritance']); 269 } 270 250 271 $xml .= " <column name=\"$col_name\"".$this->getAttributesForColumn($tb_name, $col_name, $column); 251 272 } 252 273 … … 523 544 { 524 545 foreach ($column as $key => $value) 525 546 { 526 if (!in_array($key, array('foreignClass', 'foreignTable', 'foreignReference', 'onDelete', 'onUpdate', 'index', 'unique', 'sequence' )))547 if (!in_array($key, array('foreignClass', 'foreignTable', 'foreignReference', 'onDelete', 'onUpdate', 'index', 'unique', 'sequence', 'inheritance'))) 527 548 { 528 549 $attributes_string .= " $key=\"".htmlspecialchars($this->getCorrectValueFor($key, $value), ENT_QUOTES, sfConfig::get('sf_charset'))."\""; 529 550 } 530 551 } 531 $attributes_string .= " />\n"; 552 if (isset($column['inheritance'])) 553 { 554 $attributes_string .= ' inheritance="single">'."\n"; 555 556 $extended_package = isset($this->database[$tb_name]['_attributes']['package']) ? 557 $this->database[$tb_name]['_attributes']['package'] : 558 $this->database['_attributes']['package']; 559 $extended_class = $this->database[$tb_name]['_attributes']['phpName']; 560 561 foreach ($column['inheritance'] as $key => $class) 562 { 563 $attributes_string .= sprintf(' <inheritance extends="%s.%s" key="%s" class="%s" />%s', 564 $extended_package, $extended_class, $key, $class, "\n"); 565 } 566 $attributes_string .= ' </column>'."\n"; 567 } 568 else 569 { 570 $attributes_string .= " />\n"; 571 } 532 572 } 533 573 else 534 574 {