1

我有覆盖文档(mongodb)和generator.yml的问题

文件:

<php

namespace Acme\DemoBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\Document
 */
class Product
{
    /**
     * @ODM\ReferenceOne(targetDocument="Badge")
     */
    private $badge;
}

文件:

<php

namespace Acme\TestDemoBundle\Document;

use Acme\DemoBundle\Document\Product as BaseProduct;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\Document
 */
class Product extends BaseProduct
{
    /**
     * @ODM\String
     */
    private $field;
}

当您在覆盖的生成器新模型中指定时出现问题

生成器:

generator: admingenerator.generator.doctrine_odm
params:
  model: Acme\DemoBundle\Document\Product
  namespace_prefix: Acme
  bundle_name: DemoBundle
  i18n_catalog: AcmeDemoBundle
  object_actions:
      delete: ~
  fields:
      badge:
          label: badge.label
# ......

生成器:

generator: admingenerator.generator.doctrine_odm
params:
  model: Acme\TestDemoBundle\Document\Product
  namespace_prefix: Acme
  bundle_name: DemoBundle
  i18n_catalog: AcmeDemoBundle
  object_actions:
      delete: ~
  fields:
      badge:
          label: badge.label
      field:
          label: field.label
# ......

当您在覆盖的生成器新模型中指定时,会出现问题。我设置为新的生成器模型属性Acme\TestDemoBundle\Document\Product并收到错误“预期关联名称,'徽章'不是关联。”

当他输入提交时出现问题https://github.com/symfony2admingenerator/AdmingeneratorGeneratorBundle/commit/357c0378ce7b0bafa2551148aa24fc533c6998a3

hasAssociation()来自数组中元数据检查字段的方法fieldMappings,但getAssociationTargetClass()返回表单asociationMappings数组

4

1 回答 1

0

当使用带有教义的父类时,您应该注释@ODM\MappedSuperclass。对父类使用@ODM\Document注释,子类不能代理引用,因此您必须覆盖这些属性。@ODM\Document如果您保留父注释,子文档应如下所示

<php

namespace Acme\TestDemoBundle\Document;

use Acme\DemoBundle\Document\Product as BaseProduct;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

    /**
     * @ODM\Document
     */
    class Product extends BaseProduct
    {
        /**
         * @ODM\String
         */
        private $field;

        /**
         * @ODM\ReferenceOne(targetDocument="Badge")
         */
         private $badge;


    }
于 2015-05-01T00:16:37.907 回答