自定义行为的条令迁移表创建

发布于 2024-12-22 19:06:27 字数 1672 浏览 2 评论 0原文

我已经创建了自定义的原则(1.2)行为,它应该为模型创建表(与 i18n 行为非常相似)。我在 schema.sql 中看到这个表,如果我执行它,一切都很好,但是如果我的迁移差异(教义:generate-migrations-diff),则这不是这样的表。

我做错了什么?

class DescriptionableGenerator extends Doctrine_Record_Generator
{
  protected $_options = array(
                          'className'      => '%CLASS%Description',
                          'tableName'      => '%TABLE%_description',
                          'fields'         => array(),
                          'generateFiles'  => false,
                          'table'          => false,
                          'pluginTable'    => false,
                          'children'       => array(),
                          'options'        => array(),
                          'cascadeDelete'  => true,
                          'appLevelDelete' => false
                        );

  public function  __construct(array $options = array())
  {
    $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
  }

  public function buildRelation()
  {
    $this->buildForeignRelation('Descriptions');
    $this->buildLocalRelation();
  }

  public function setTableDefinition()
  {
    $this->hasColumn('lang', 'char', '2', array('notnull' => true));
    $this->hasColumn('field', 'string', '255', array('notnull' => true));
    $this->hasColumn('title', 'string', '255', array('notnull' => true));
    $this->hasColumn('description', 'clob');
    $this->hasColumn('compulsory', 'boolean', 1, array('notnull' => true, 'default' => 0));

    $this->addListener(new DescriptionableListener());
  }
}

I've created custom doctrine(1.2) behavior which should create tables for models (very simmilar to i18n behavior). I see this tables in schema.sql, and if i execute it everything is fine, but this is no such tables if my migrations diff (doctrine:generate-migrations-diff).

What i'm doing wrong?

class DescriptionableGenerator extends Doctrine_Record_Generator
{
  protected $_options = array(
                          'className'      => '%CLASS%Description',
                          'tableName'      => '%TABLE%_description',
                          'fields'         => array(),
                          'generateFiles'  => false,
                          'table'          => false,
                          'pluginTable'    => false,
                          'children'       => array(),
                          'options'        => array(),
                          'cascadeDelete'  => true,
                          'appLevelDelete' => false
                        );

  public function  __construct(array $options = array())
  {
    $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
  }

  public function buildRelation()
  {
    $this->buildForeignRelation('Descriptions');
    $this->buildLocalRelation();
  }

  public function setTableDefinition()
  {
    $this->hasColumn('lang', 'char', '2', array('notnull' => true));
    $this->hasColumn('field', 'string', '255', array('notnull' => true));
    $this->hasColumn('title', 'string', '255', array('notnull' => true));
    $this->hasColumn('description', 'clob');
    $this->hasColumn('compulsory', 'boolean', 1, array('notnull' => true, 'default' => 0));

    $this->addListener(new DescriptionableListener());
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风流物 2024-12-29 19:06:27

解决了!

由于命令“php symfonydoctrine:build-model”而出现问题。
因此,如果您遇到同样的问题,您应该:

  1. 从架构中删除您的行为。
  2. 执行“php symfony 主义:build-model”。
  3. 将您的行为添加到架构中。
  4. 运行“php symfony 学说:generate-migrations-diff”。

干杯! %)

Solved!

Problem appears due to command "php symfony doctrine:build-model".
So, if you have the same problem you should:

  1. Remove your behavior from schema.
  2. Execute "php symfony doctrine:build-model".
  3. Add your behavior to schema.
  4. Run "php symfony doctrine:generate-migrations-diff".

Chears! %)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文