Development

#3473: propel-inheritance.patch

You must first sign up to be able to contribute.

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  
    4747require_once(dirname(__FILE__).'/../../../../util/sfToolkit.class.php'); 
    4848require_once(dirname(__FILE__).'/../../../../yaml/sfYaml.class.php'); 
    4949 
    50 $t = new my_lime_test(261, new lime_output_color()); 
     50$t = new my_lime_test(277, new lime_output_color()); 
    5151 
    5252$t->diag('Classical YAML to XML conversion'); 
    5353$p = new sfPropelDatabaseSchema(); 
  • lib/plugins/sfPropelPlugin/test/unit/fixtures/schema.xml

    old new  
    44  <table name="ab_group" phpName="Group" package="foo.bar.lib.model" isI18N="true" i18nTable="ab_group_i18n"> 
    55    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> 
    66    <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> 
    711  </table> 
    812 
    913  <table name="cd_user" phpName="User" isI18N="true" i18nTable="cd_user_i18n"> 
  • lib/plugins/sfPropelPlugin/test/unit/fixtures/schema.yml

    old new  
    44    _attributes:    { phpName: Group, package: foo.bar.lib.model } 
    55    id: 
    66    name:           varchar(50) 
     7    type:           varchar(50) 
     8    _inheritance: 
     9      column:       type 
     10      classes: 
     11        tight:      Group_Tight 
     12        loose:      Group_Loose 
    713     
    814  cd_user: 
    915    _attributes:    { phpName: User, isI18N: true, i18nTable: cd_user_i18n } 
  • lib/plugins/sfPropelPlugin/test/unit/fixtures/new_schema.yml

    old new  
    1010    columns: 
    1111      id: 
    1212      name:           varchar(50) 
     13      type:           varchar(50) 
     14    inheritance: 
     15      column:         type 
     16      classes: 
     17        tight:        Group_Tight 
     18        loose:        Group_Loose 
    1319   
    1420  User: 
    1521    tableName:        cd_user 
  • lib/plugins/sfPropelPlugin/lib/propel/sfPropelDatabaseSchema.class.php

    old new  
    116116            case '_behaviors': 
    117117              $classes[$phpName]['behaviors'] = $column_params; 
    118118              break; 
     119            case '_inheritance': 
     120              $classes[$phpName]['inheritance'] = $column_params; 
     121              break; 
    119122            case '_foreignKeys': 
    120123              $classes[$phpName]['foreignKeys'] = $column_params; 
    121124              break; 
     
    191194          unset($classParams['behaviors']); 
    192195        } 
    193196         
     197        // Inheritance 
     198        if (isset($classParams['inheritance'])) 
     199        { 
     200          $tableParams['_inheritance'] = $classParams['inheritance']; 
     201          unset($classParams['inheritance']); 
     202        } 
     203         
    194204        // Table attributes 
    195205        $tableAttributes = array(); 
    196206        if (isset($classParams['tableName'])) 
     
    247257      // columns 
    248258      foreach ($this->getChildren($table) as $col_name => $column) 
    249259      { 
     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         
    250271        $xml .= "    <column name=\"$col_name\"".$this->getAttributesForColumn($tb_name, $col_name, $column); 
    251272      } 
    252273 
     
    523544    { 
    524545      foreach ($column as $key => $value) 
    525546      { 
    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'))) 
    527548        { 
    528549          $attributes_string .= " $key=\"".htmlspecialchars($this->getCorrectValueFor($key, $value), ENT_QUOTES, sfConfig::get('sf_charset'))."\""; 
    529550        } 
    530551      } 
    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      } 
    532572    } 
    533573    else 
    534574    {