PHP Doctrine - YAML 语法帮助。多对多关系的默认值?
我有以下 YAML 架构用于在 Doctrine 中组织用户:
Person:
tableName: people
columns:
id:
type: integer
primary: true
autoincrement: true
firstname:
type: string
notnull: true
lastname:
type: string
notnull: true
User:
inheritance:
extends: Person
type: column_aggregation
keyField: type
keyValue: 1
Userdetails:
columns:
person_id:
type: integer
primary: true
password:
type: string
notnull: true
relations:
User:
foreignType: one
local: person_id
onDelete: CASCADE
onUpdate: CASCADE
Group:
tableName: groups
columns:
id:
type: integer
primary: true
autoincrement: true
name:
type: string
notnull: true
UserGroup:
columns:
group_id:
type: integer
primary: true
person_id:
type: integer
primary: true
relations:
User:
foreignType: many
local: person_id
Group:
foreignType: many
基本上,任何用户都将属于一个或多个组。
有什么方法可以默认将新用户添加到特定组吗?
任何建议表示赞赏。
谢谢
I have the following YAML schema for organising users in Doctrine:
Person:
tableName: people
columns:
id:
type: integer
primary: true
autoincrement: true
firstname:
type: string
notnull: true
lastname:
type: string
notnull: true
User:
inheritance:
extends: Person
type: column_aggregation
keyField: type
keyValue: 1
Userdetails:
columns:
person_id:
type: integer
primary: true
password:
type: string
notnull: true
relations:
User:
foreignType: one
local: person_id
onDelete: CASCADE
onUpdate: CASCADE
Group:
tableName: groups
columns:
id:
type: integer
primary: true
autoincrement: true
name:
type: string
notnull: true
UserGroup:
columns:
group_id:
type: integer
primary: true
person_id:
type: integer
primary: true
relations:
User:
foreignType: many
local: person_id
Group:
foreignType: many
Basically, any people who are users will belong to one or more groups.
Is there any way to add new users to a particular group by default?
Any advice appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须管理,我不再使用最新的 Doctrine 版本,但由于它的记录需要默认构造函数,我认为从用户构造函数中的数据库加载默认组应该足够了,具体
取决于您可能想要的架构考虑将该初始化也放入您的控制器中。
I must admin, that I'm not in the most recent Doctrine version anymore, but since its records need a default constructor I think it should be sufficient to load the default group from the database in the users constructor
Depending on your architecture you might want to consider to put that initialisation into your controller, too.