Development

Changeset 5548

You must first sign up to be able to contribute.

Changeset 5548

Show
Ignore:
Timestamp:
10/16/07 18:23:23 (1 year ago)
Author:
francois
Message:

sfPropelAlternativeSchemaPlugin Added a way to define behaviors from within the schema

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelAlternativeSchemaPlugin/README

    r5519 r5548  
    152152}}} 
    153153 
     154== Behaviors == 
     155 
     156The new schema syntax alows you to define behaviors directly from the schema itself. To allow the support for these schema behaviors, you must add this line at the end of all your application's `config.php`: 
     157 
     158{{{ 
     159// In apps/myapp/config/config.php 
     160sfPropelAlternativeSchema::initializeBehaviors(); 
     161}}} 
     162 
     163Now you can add a `behaviors` section for each class that you define in a schema, as follows: 
     164 
     165{{{ 
     166classes: 
     167  Article: 
     168    behaviors: 
     169      paranoid: { column: deleted_at } 
     170}}} 
     171 
     172Of course, don't forget to rebuild the model after you modify your schema. 
     173 
     174This feature groups the behaviors declarations into a single file called `behaviors.php`, located under the `cache/` directory, for maximum efficiency. This file will be regenerated during the first request after each model rebuild. 
     175 
     176Note that this feature will also add `.behaviors` files under your project's `config/` directory. These are generated by the `propel-build-model` task and should not be deleted, otherwise the behaviors will not work when you transfer the project to another host and clear the cache manually. 
     177 
    154178== Customizing an existing schema == 
    155179 
     
    201225    tableName:        ab_group 
    202226    package:          foo.bar.lib.model 
     227    behaviors:        [paranoid] 
    203228    columns: 
    204229      id: 
     
    223248    tableName:        ab_group 
    224249    package:          foo.bar.lib.model 
     250    behaviors:        [paranoid] 
    225251    columns: 
    226252      id: 
     
    263289}}} 
    264290 
    265 == TODO == 
    266  
    267  * Manage behaviors directly in the schema 
    268   
    269291== Changelog == 
    270292 
    271293=== Trunk === 
    272294 
     295 * francois: Added a way to define behaviors from the schema 
    273296 * francois: Added a new `foreignClass` column attribute to define a foreign key from a phpName rather than from a tableName 
    274297 * francois: Added section about plugin check in README 
  • plugins/sfPropelAlternativeSchemaPlugin/lib/sfPropelDatabaseSchema.class.php

    r5519 r5548  
    9191  public function loadNewYaml($schema) 
    9292  { 
     93    sfPropelAlternativeSchema::cleanBehaviorsOnce(); 
     94     
    9395    if(isset($schema['connection'])) 
    9496    { 
     
    135137        } 
    136138         
     139        // Behaviors 
     140        if(isset($classParams['behaviors'])) 
     141        { 
     142          sfPropelAlternativeSchema::addBehaviors($className, $classParams['behaviors']); 
     143          unset($classParams['behaviors']); 
     144        }         
     145         
    137146        // Table attributes 
    138147        $tableAttributes = array(); 
     
    254263        } 
    255264      } 
    256  
     265       
    257266      $xml .= "  </table>\n"; 
    258267    } 
  • plugins/sfPropelAlternativeSchemaPlugin/package.xml

    r5415 r5548  
    3232     <dir name="lib"> 
    3333       <file role="data" name="sfPropelDatabaseSchema.class.php" /> 
     34       <file role="data" name="sfPropelAlternativeSchema.class.php" /> 
    3435     </dir> 
    3536 
  • plugins/sfPropelAlternativeSchemaPlugin/test/unit/sfPropelDatabaseSchemaTest.php

    r5519 r5548  
    1010 
    1111include(dirname(__FILE__).'/../../../../test/bootstrap/unit.php'); 
     12 
     13class sfPropelAlternativeSchema 
     14{ 
     15  static function cleanBehaviorsOnce() 
     16  { 
     17     
     18  } 
     19} 
    1220 
    1321class my_lime_test extends lime_test