Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change model builder options

I'm trying to get symfony to use a custom class called jsDoctrineRecord instead of sfDoctrineRecord for its models. Here's the code for the overriding class:

<?php
abstract class jsDoctrineRecord extends sfDoctrineRecord
{
  public function foo()
  {
    echo 'foo';exit;
  }
}

Here's what I have in config/ProjectConfiguration.class.php, per the instructions here:

<?php

require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins('sfDoctrinePlugin');
    $this->enablePlugins('sfDoctrineGuardPlugin');
    $this->enablePlugins('jsDoctrineSchemaOverriderPlugin');
  }

  public function configureDoctrine(Doctrine_Manager $manager)
  {
    $options = array('baseClassName' => 'jsDoctrineRecord');
    sfConfig::set('doctrine_model_builder_options', $options);
  }
}

Unfortunately, this doesn't work. My models continue to inherit from sfDoctrineRecord instead of jsDoctrineRecord. The foo() method is not recognized. I still have the problem when I clear my cache.

I'm pretty sure I'm following the instructions right, so what could be going wrong?

like image 413
Jason Swett Avatar asked Feb 12 '26 16:02

Jason Swett


2 Answers

Im not sure whay thats not working as its still there for BC, but after looking at the sfDoctrinePlugin it looks like the proper way to handle this is with a symfony event listener (see lines 83 - 89 of SF_LIB_DIR/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php):

in projectConfiguration:

public function setup()
{
   $this->enablePlugins('sfDoctrinePlugin');
   $this->enablePlugins('sfDoctrineGuardPlugin');
   $this->enablePlugins('jsDoctrineSchemaOverriderPlugin');

   $this->dispatcher->connect(
     'doctrine.filter_model_builder_options', 
     array($this, 'configureDoctrineBuildOptions')
   );
}

public function configureDoctrineBuildOptions(sfEvent $event, $options)
{
   $options['baseClassName'] = 'jsDoctrineRecord';

   return $options;
}

Give that a shot and see if it makes a difference.

like image 146
prodigitalson Avatar answered Feb 15 '26 05:02

prodigitalson


You need to rebuild the model so that the Base record classes extend your new record class. Run doctrine:build-model.

like image 32
Jeremy Kauffman Avatar answered Feb 15 '26 05:02

Jeremy Kauffman