[英]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.