使用原则和 symfony 建立弱关系

发布于 2024-12-03 19:35:28 字数 1793 浏览 0 评论 0原文

我想做的是我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2024-12-10 19:35:28

据我所知,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文