我遇到覆盖文档(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
并收到错误“预期的关联名称,'徽章'不是关联。”
方法hasAssociation()
来自fieldMappings
数组中的元数据检查字段,但getAssociationTargetClass()
返回表单asociationMappings
数组
答案 0 :(得分: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;
}