使用原则和 symfony 建立弱关系
我想做的是我的User
表和我的Confirmation
表之间的弱关系,Confirmation
弱于User
>。为了表示它,我的架构如下:
User:
actAs: [Timestampable]
connection: doctrine
tableName: User
columns:
id:
type: integer
primary: true
autoincrement: true
username:
type: string(50)
notnull: true
name:
type: string(50)
notnull: true
.
.
.
indexes:
myindex1:
fields:
username:
sorting: ASC
length: 50
type: unique
relations:
Confirmation:
foreignType: one
attributes:
export: all
validate: true
Confirmation:
actAs: [Timestampable]
connection: doctrine
tableName: Confirmation
columns:
user_id:
type: integer
primary: true
hash:
type: string(64)
notnull: true
relations:
User:
local: user_id
foreign: id
type: one
foreignType: one
当运行命令 $ php symfonydoctrine:build --all --no-confirmation
时,我在输出中收到此错误:
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'id' doesn't exist in table. Failing Query: "CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB". Failing Query: CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB
所以,看来doctrine是在未定义的字段 (id
) 上生成索引,如 INDEX id_idx (id)
中所示。为什么学说要生成这个索引?我怎样才能塑造我想要的东西?
学说文档在关系问题上并不是很广泛,任何指向良好文档网站的链接也将非常感激...
提前感谢您的任何帮助!
what im trying to do is a weak relationship between my User
table and my Confirmation
table, being Confirmation
weak of User
. To represent it, my schema is as follows:
User:
actAs: [Timestampable]
connection: doctrine
tableName: User
columns:
id:
type: integer
primary: true
autoincrement: true
username:
type: string(50)
notnull: true
name:
type: string(50)
notnull: true
.
.
.
indexes:
myindex1:
fields:
username:
sorting: ASC
length: 50
type: unique
relations:
Confirmation:
foreignType: one
attributes:
export: all
validate: true
Confirmation:
actAs: [Timestampable]
connection: doctrine
tableName: Confirmation
columns:
user_id:
type: integer
primary: true
hash:
type: string(64)
notnull: true
relations:
User:
local: user_id
foreign: id
type: one
foreignType: one
When running the command $ php symfony doctrine:build --all --no-confirmation
, i got this error in the output:
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'id' doesn't exist in table. Failing Query: "CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB". Failing Query: CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB
so, it seems doctrine is generating an index over a field that was not defined (id
) as you can see in INDEX id_idx (id)
. Why is doctrine generating this index? how can i model what i want?
doctrine documentation is not very extensive in relationships matters, any link to a good documentation site would be very appreciated too...
Thanks in advance for any help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,Doctrine 会自动将默认情况下的“id”列添加到(所有)表中。
此行为已记录多次,您可以配置此列:
但是,抱歉,我不知道是否有办法禁用此功能。
As far as i know, Doctrine will automatically add a column "id" per default to (all of) your table(s).
This behaviour is documented several times, and you can configure this column :
But, i'm sorry, i'dont know, if there is a way to disable this feature.