Symfony 1.4, doctrine: multiple join to one table

那年仲夏 提交于 2020-02-07 12:20:17

问题


the scheme:

User:
  options:
    collate: utf8_unicode_ci
    charset: utf8
  tableName: users
  columns:
    ID:
      type: integer(4)
      primary: true
      autoincrement: true
    USERNAME:
      type: string(255)
      notnull: true

Task:
  options:
    collate: utf8_unicode_ci
    charset: utf8
  tableName: tasks
  columns:
    ID:
      type: integer(4)
      primary: true
      autoincrement: true
    CREATED_ID:
      type: integer(4)
      notnull: true
    OWNER_ID:
      type: integer(4)
      notnull: true
    DESCRIPTION:
      type: text
      notnull: true
  relations:
    User:
      onDelete: CASCADE
      local: CREATED_ID
      foreign: ID
    User:
      onDelete: CASCADE
      local: OWNER_ID
      foreign: ID

as you can see, the Task.OWNER_ID and Task.CREATED_ID points at User.ID - Still, only OWNER_ID appears as foreign key in the actual SQL table:

CREATE TABLE  `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE  `tasks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created_id` int(11) NOT NULL,
  `owner_id` int(11) NOT NULL,
  `description` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `owner_id_idx` (`owner_id`),
  CONSTRAINT `tasks_owner_id_users_id` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Symfony doesnt drop any error. Am I not allowed to define more join to a table?


回答1:


Your scheme is ... not really correct. Try this

  relations:
    UserCreator:
      class: User
      onDelete: CASCADE
      local: CREATED_ID
      foreign: ID
      foreignAlias: Tasks
    UserOwner:
      class: User
      onDelete: CASCADE
      local: OWNER_ID
      foreign: ID
      foreignAlias: Tasks


来源:https://stackoverflow.com/questions/14071955/symfony-1-4-doctrine-multiple-join-to-one-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!