【发布时间】:2018-02-01 16:04:33
【问题描述】:
我正在使用一个现有的数据库(来自我的公司),他们想用 symfony 4 构建一个内部网。
我创建了我的学说文件和学说数据库。
之后,我使用了一些插入命令来处理教义数据库和我的 symfony 项目中现有数据库中的所有数据。
目前一切正常!
但我现在想在我的学说模型中添加一个关系映射(一对多、多对一、多对多)。
在我发现的所有示例中,它们将模型彼此链接到夹具内或与一些新数据插入数据库中
所以我在 Bodyshops.orm.yml 链接中添加了一个一对一的单向关系到 BodyshopsEmail.orm.yml,然后使用了
doctrine:schema:update --force
成功后,我想在控制器中使用我的 Bodyshops 模型,我得到了一个
App\Entity\BodyshopsEmail 上的主键 senderEmail 缺少值
我知道问题被提出了
但我猜错误在这里是因为我的 bodyshopsEmail id 中有两个 ID(与 bodyshops.id 相同)和 senderMail(在 bodyshopsEmail 中设置 foreach 行)
我想知道我是否必须制作一个脚本来绑定我的实际数据关系映射以避免错误,或者错误不是来自链接而是来自 orm.yml 示例强>
希望我足够清楚,感谢阅读:p 我的文件在下面
(英文)
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html
(法国)
https://www.jdecool.fr/blog/2017/09/20/tutorial-jobeet-symfony-4-partie-3a-le-modele-de-donnees.html
Bodyshops.orm.yml
App\Entity\Bodyshops:
type: entity
id:
id: #B
type: string
length: 2
fields:
accessFrom:
type: string
length: 5
nullable: false
region:
type: string
length: 8
nullable: false
name:
type: string
length: 32
nullable: false
nameAlternative:
type: string
length: 32
nullable: false
nameCode:
type: string
length: 32
nullable: false
phone:
type: string
length: 16
nullable: true
fax:
type: string
length: 16
nullable: true
website:
type: string
length: 64
nullable: true
address1:
type: string
length: 64
nullable: false
address2:
type: string
length: 64
nullable: true
address3:
type: string
length: 64
nullable: true
zip:
type: string
length: 6
nullable: false
city:
type: string
length: 32
nullable: false
country:
type: string
length: 32
nullable: false
countryCode:
type: string
length: 4
nullable: false
colorBackground:
type: string
length: 8
nullable: false
colorText:
type: string
length: 8
nullable: true
workshopSlots:
type: integer
length: 4
nullable: false
departements:
type: string
length: 32
nullable: false
ipList:
type: json_array
nullable: true
identRepa:
type: string
length: 32
nullable: true
statutJurid:
type: string
length: 2
nullable: true
capital:
type: string
length: 16
nullable: true
natInscript:
type: string
length: 64
nullable: true
rcsRdm:
type: string
length: 10
nullable: true
gerant:
type: string
length: 1
nullable: true
codeApe:
type: string
length: 4
nullable: true
idIntracomm:
type: string
length: 13
nullable: true
oneToOne:
email:
targetEntity: BodyshopsEmail
joinColumn:
name: id
referencedColumnName: id
BodyshopsEmail.orm.yml
App\Entity\BodyshopsEmail:
type: entity
id:
id:
type: string
length: 2
nullable: false
senderEmail:
type: string
length: 64
nullable: false
fields:
senderName:
type: string
length: 64
nullable: false
replyTo:
type: string
length: 64
nullable: true
smtpHost:
type: string
length: 32
nullable: false
smtpPort:
type: string
length: 6
nullable: false
smtpLogin:
type: string
length: 64
nullable: false
smtpAuth:
type: string
length: 32
nullable: false
smtpSecurity:
type: string
length: 32
nullable: true
popHost:
type: string
length: 32
nullable: true
popPort:
type: string
length: 6
nullable: true
imapHost:
type: string
length: 32
nullable: false
imapPort:
type: string
length: 6
nullable: false
receiveLogin:
type: string
length: 64
nullable: false
receiveAuth:
type: string
length: 32
nullable: false
receiveSecurity:
type: string
length: 32
nullable: false
globalPassword:
type: string
length: 64
nullable: false
signatureFile:
type: string
length: 256
nullable: true
我认为向您展示模型没有用,但请确保每个值都作为 getter 和 setter(甚至 $email 由一对一定义)
【问题讨论】:
-
a script that will bind my actual data relationship mapping是什么意思? -
在每个模型中设置新关系的脚本
标签: database symfony doctrine-orm doctrine