我有一个卡片实体,与用户实体有一个关系
MyBundle\Entity\Card:
type: entity
table: mm_card
repositoryClass: CardRepository
id:
id:
type: integer
nullable: false
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
code:
type: string
nullable: false
length: 16
manyToOne:
company:
targetEntity: User
inversedBy: companyCards
joinColumn:
name: company_id
referencedColumnName: id
nullable: false
onDelete: cascade
createdBy:
targetEntity: User
joinColumn:
name: created_by
referencedColumnName: id
nullable: true
gedmo:
blameable:
on: create
updatedBy:
targetEntity: User
joinColumn:
name: updated_by
referencedColumnName: id
nullable: true
gedmo:
blameable:
on: update
oneToOne:
owner:
targetEntity: User
joinColumn:
name: owner_id
referencedColumnName: id
nullable: true
onDelete: SET NULL
当我使用带有表单的标准CRUD来编辑卡类时,我在那里有EntityType:class,当我选择用户并保存它时可以使用。但是如果在API中我想要做同样的事情,那么id不会:
$cardObj = $em->getRepository('MyBundle:Card')->find(16);
$userObj = $em->getRepository('MyBundle:User')->find(10);
$cardObj->setOwner($userObj);
$em->flush();
我在DB中遇到错误:
An exception occurred while executing 'INSERT INTO user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, maccount_type, mcompany_type, mphoto, mphoto_guid, mcompany_code, billing_first_name, billing_last_name, billing_company, billing_phone, billing_country, billing_street, billing_building_nb, billing_local_nb, billing_city, billing_state, billing_postcode, mdescription, wp_user_id, master_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)':\n\nSQLSTATE[HY093]: Invalid parameter number: no parameters were bound
有没有人知道出了什么问题以及如何解决它?
答案 0 :(得分:0)
你有什么问题.yaml配置。
查看官方documentation中的示例。 例如:
Product: type: entity oneToOne: shipping: targetEntity: Shipping joinColumn: name: shipping_id referencedColumnName: id