有关doctrine文件的定义(.yml)
如果两个对象之间没有关系,那么最为简单就什么也不写
如果两个对象存在一对一的关系
例如司机和卡车,那么可以在卡车或司机段任意定义(司机)
relations
Car: {local: car_id, foreign id,foreignAlias: car}
如果两个对象存在一对多的关系
例如学生和校长的关系,我们一般是在多方定义关系
relations:
Leader: {onDelete: CASCADE, local: leader_id, foreign id,foreignAlias: Students}
如果两个对象存在多对多的关系,这种情况比较复杂,我们需要首先创建出一个公共的关系类(老师和学生)
StudentTearcher:
columns:
student_id: {type: integer,primary: true}
tearcher_id: {type: integer,primary: true}
relations:
Student: {onDelete: CASCADE, local: student_id, foreign: id }
Tearcher: {onDelete: CASCADE, local: tearcher_id, foreign: id}
然后再学生端
relations:
Tearchers:
class: Tearche
refClass: StudentTearcher
local: student_id
foreign: tearcher_id
foreignAlias: Student
如果两个对象之间没有关系,那么最为简单就什么也不写
如果两个对象存在一对一的关系
例如司机和卡车,那么可以在卡车或司机段任意定义(司机)
relations
Car: {local: car_id, foreign id,foreignAlias: car}
如果两个对象存在一对多的关系
例如学生和校长的关系,我们一般是在多方定义关系
relations:
Leader: {onDelete: CASCADE, local: leader_id, foreign id,foreignAlias: Students}
如果两个对象存在多对多的关系,这种情况比较复杂,我们需要首先创建出一个公共的关系类(老师和学生)
StudentTearcher:
columns:
student_id: {type: integer,primary: true}
tearcher_id: {type: integer,primary: true}
relations:
Student: {onDelete: CASCADE, local: student_id, foreign: id }
Tearcher: {onDelete: CASCADE, local: tearcher_id, foreign: id}
然后再学生端
relations:
Tearchers:
class: Tearche
refClass: StudentTearcher
local: student_id
foreign: tearcher_id
foreignAlias: Student
本文介绍了使用 Doctrine ORM 通过 YAML 文件定义不同类型的实体间关系的方法,包括一对一、一对多及多对多关系,并提供了具体的配置示例。
1236

被折叠的 条评论
为什么被折叠?



