Symfony 条令实体缺少指定的ID
我有两个实体,Contact和GlobalSymfony 条令实体缺少指定的ID,symfony,doctrine-orm,Symfony,Doctrine Orm,我有两个实体,Contact和Global Example\EventBundle\Entity\EventGlobal: type: entity table: EventGlobal fields: id: id: true type: integer generator: strategy: AUTO oneToOne:
Example\EventBundle\Entity\EventGlobal:
type: entity
table: EventGlobal
fields:
id:
id: true
type: integer
generator:
strategy: AUTO
oneToOne:
EventKontakt:
targetEntity: Example\EventBundle\Entity\EventContact
mappedBy: EventGlobal
cascade: ["persist"]
Example\EventBundle\Entity\EventContact:
type: entity
table: EventContact
fields:
EventGlobal_id:
id: true
type: integer
oneToOne:
EventGlobal:
targetEntity: Example\EventBundle\Entity\EventGlobal
inversedBy: EventContact
joinColumns:
EventGlobal_id:
referencedColumnName: id
nullable: false
他们工作得很好。现在我用Symfony构建一个表单
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add(Stuff..)
->add('EventContact', new EventContactType($this->options))
;
}
表单正确呈现,具有一对一的关系。
但是当我保存的时候,我得到了一个错误
我的错误是:
Entity of type Example\EventBundle\Entity\EventContact is missing an assigned ID. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.
我怎样才能保证我的安全是由Symfony/条令完成的 您需要为EventContact添加生成器 对于您的EventContact实体
fields:
EventGlobal_id:
id: true
type: integer
generator:
strategy: AUTO
如果我只生成一个eventglobal而不生成eventcontact一次,然后返回以生成两个,则会部分起作用。id被破坏,链接到最后一个条目。