【问题标题】:Association name expected, 'badge' is not an association应为关联名称,“徽章”不是关联
【发布时间】:2014-08-29 06:59:30
【问题描述】:

我对覆盖文档 (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 并收到错误 “Association name expected, 'badge' is not an association.”

当他输入commit https://github.com/symfony2admingenerator/AdmingeneratorGeneratorBundle/commit/357c0378ce7b0bafa2551148aa24fc533c6998a3时问题来了

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

【问题讨论】:

    标签: mongodb symfony doctrine-orm admin-generator


    【解决方案1】:

    当使用带有教义的父类时,您应该注释@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;
    
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多