【发布时间】:2015-09-21 20:42:35
【问题描述】:
我们正在将一个应用程序移植到 Symfony2 并且目前使用理论 ORM 卡住了。我们在数据库中有一堆错误的外键,并且在不遇到“找不到实体”异常的情况下进行关系映射变得越来越困难。它在清理数据库的路线图上,但不幸的是,这不是我们现在可以解决的问题。如果找不到正确的实体,有什么办法可以让它返回 null 吗?
如果我有如下关系映射:
User:
type: entity
table: user
id:
userID:
type: integer
generator:
strategy: NONE
fields:
contactName:
type: string
length: 255
nullable: false
contactPhone:
type: string
length: 255
nullable: false
companyName:
type: string
length: 255
nullable: false
username:
type: string
length: 255
nullable: false
password:
type: string
length: 255
nullable: false
email:
type: string
length: 255
nullable: false
manyToOne:
address:
targetEntity: Address
joinColumn:
name: addressID
referencedColumnName: addressID
nullable: true
default: null
-----------------------------------------------------
Address:
type: entity
table: address
id:
addressID:
type: integer
generator:
strategy: AUTO
fields:
street:
type: string
length: 255
nullable: false
street2:
type: string
length: 255
nullable: false
city:
type: string
length: 255
nullable: false
state:
type: string
length: 32
nullable: false
zip:
type: string
length: 10
nullable: false
country:
type: string
length: 40
nullable: false
似乎如果用户表中的 addressID 值错误,我会得到“找不到实体”。通过序列化程序发送时出现异常。
【问题讨论】:
标签: php symfony doctrine-orm