[英]symfony2 : cannot insert in one-to-one relation merge form
客户实体与信用实体具有一对一关系。 当我尝试插入时,出现以下错误:
*
Jobeet \\ JobBundle \\ Entity \\ Credit类型的实体缺少为字段“ id”分配的ID。 该实体的标识符生成策略要求在调用EntityManager#persist()之前填充ID字段。 如果要自动生成的标识符,则需要相应地调整元数据映射。
*
我想念什么?
Customer.orm.yml
type: entity
table: customer
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
nullable: true
address:
type: string
length: 255
oneToOne:
credit:
targetEntity: Credit
mappedBy: customer
cascade: [persist]
信用额度
type: entity
table: credit
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
customer_id:
type: integer
unique: true
nullable: false
credit_name:
type: string
length: 255
nullable: true
credit_desc:
type: string
length: 255
nullable: true
oneToOne:
customer:
targetEntity: Customer
inversedBy: credit
joinColumn:
name: customer_id
referencedColumnName: id
CustomerType.php
class CustomerType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('address')
->add('credit', new CreditType())
;
}
}
尝试将Credit.orm.yml更改为
type: entity
table: credit
id:
id:
type: integer
unique: true
column: other_non_conflict_column_name
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.