鉴别符列可以成为Doctrine2中主键的一部分吗? [英] Can a Discriminator Column be part of the Primary Key in Doctrine2?

查看:75
本文介绍了鉴别符列可以成为Doctrine2中主键的一部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用,用于存储多个服务的OAuth凭据.我想使用服务的ID作为主键;但是,这并非在所有服务中都是唯一的.

I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services.

我已经将数据库设置为使用discriminator列和服务的id作为主键,但是我找不到让Doctrine使用discriminator列作为键的方法(除了discriminator列).我正在使用docblock批注,并且如果将discriminator列添加为@Id字段,则会出现错误:

I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine use the discriminator column as the key (in addition to the discriminator column). I'm using docblock annotations, and if I add the discriminator column as an @Id field I get an error:

Duplicate definition of column...in a field or discriminator column mapping.

如果仅将字段定义为区分符列,则任何重叠的服务ID都会更新所有匹配的行.

If I only define the field as the discriminator column, any overlapping service ids update all the matching rows.

除了使用自动生成的it值以外,是否还可以使此工作正常进行?

Anyway to make this work, other than just using an autogenerated it value?

推荐答案

您不能,descriminator列不能用作主键的一部分.

You can't, the descriminator column can't be used as part of the primary key.

为什么这个用例btw需要STI?您必须为您提供的每个开放ID服务创建一个新类,听起来很烦人:-)

Why do you need STI for this use-case btw? You have to create one new class per open-id service you provide, sounds pretty annoying :-)

这篇关于鉴别符列可以成为Doctrine2中主键的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆