Listing 2281
Submitted by jose, 29 June 2009
class DomainRelatedBehavior extends Doctrine_Record_Generator { public function initOptions() { $this->setOption('className', '%CLASS%Domain'); $this->setOption('related_table', Doctrine::getTable('Domain') ); $this->setOption('generateFiles', true ); $this->setOption('generatePath', dirname(__FILE__)."/../../" ); $this->setOption('builderOptions', array ( 'baseClassesDirectory' => 'base' ) ); } public function setTableDefinition() { $class_table = $this->_options['table']; $related_table = $this->_options['related_table']; $this->hasColumn('id', 'integer', 11, array ('type'=>'integer', 'length'=>11, 'primary'=>true, 'autoincrement'=>true)); $this->hasColumn( $related_table->getTableName().'_id', 'integer',11 , array ('type'=>'integer', 'length'=>11, 'notnull' => true) ); $this->hasColumn( $class_table->getTableName().'_id', 'integer', 11 ,array ('type'=>'integer', 'length'=>11, 'notnull' => true) ); } public function setUp (){ $this->actAs( new Doctrine_Template_Timestampable() ); $this->actAs(new Userable()); } public function buildForeignRelation($alias = null) { $class_table = $this->_options['table']; $related_table = $this->_options['related_table']; $options = array ( 'type'=>Doctrine_Relation::MANY, 'local'=>$related_table->getTableName().'_id', 'foreign'=>$class_table->getTableName().'_id', 'refClass'=> $this->_table->getComponentName() ); $related_table->getRelationParser()->bind( $class_table->getComponentName().' as '.$class_table->getTableName(), $options ); } }

