Postgres 中的 Doctrine 1.2 类自引用在保存时抛出 SQL 错误
我正在尝试对可以被其他用户邀请的用户进行建模。所以我在我的学说模型中设置了一对多的自我引用。
User:
tableName: users
actAs:
Timestampable:
columns:
id:
type: integer(11)
primary: true
autoincrement: true
name:
type: string(255)
unique: true
password:
type: string(255)
email:
type: string(255)
[...]
invited_by:
type: integer(11)
relations:
Inviter:
class: User
type: one
local: invited_by
foreign: id
foreignAlias: Invitees
onDelete: SET NULL
onUpdate: CASCADE
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
这在 MySQL 中工作得很好,但如果我尝试在 Postgres 中使用用户对象 save() 方法保存记录,则会引发以下错误:
SQLSTATE[42P01]:未定义的表:7 FEHLER:关系»users_id« exitiert nicht 第 1 行:选择 CURRVAL('users_id') ^.查询失败: “选择 CURRVAL('users_id')”
我认为这与自我引用有关,但我在建模中找不到错误。有人对此有什么想法吗?
I'm trying to model a user which could be invited by another user. So I set up one-to-many self reference in my doctrine model.
User:
tableName: users
actAs:
Timestampable:
columns:
id:
type: integer(11)
primary: true
autoincrement: true
name:
type: string(255)
unique: true
password:
type: string(255)
email:
type: string(255)
[...]
invited_by:
type: integer(11)
relations:
Inviter:
class: User
type: one
local: invited_by
foreign: id
foreignAlias: Invitees
onDelete: SET NULL
onUpdate: CASCADE
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
This works just fine in MySQL, but if I try to save the record using the User objects save()-method in Postgres the following error is thrown:
SQLSTATE[42P01]: Undefined table: 7 FEHLER: Relation »users_id«
existiert nicht LINE 1: SELECT CURRVAL('users_id') ^. Failing Query:
"SELECT CURRVAL('users_id')"
I think it is something related to the self reference, but I can't find a mistake in my modeling. Anyone an idea on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
附加到 serial 列是
tablename_colname_seq
currval
用于检索“序列的当前值”。所以它必须是:
你的整个语法显然是为 MySQL 设计的。像
type: InnoDB
、integer(11)
或autoincrement
这样的东西在 Postgres 中没有意义。The default name of a sequence attached to a serial column is
tablename_colname_seq
currval
is for retrieving the "current value" of a sequence.So it would have to be:
Your whole syntax is obviously made out for MySQL. Things like
type: InnoDB
,integer(11)
orautoincrement
don't make sense in Postgres.