0

方案:

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

如您所见,Task.OWNER_ID 和 Task.CREATED_ID 指向 User.ID - 不过,在实际 SQL 表中,只有 OWNER_ID 显示为外键:

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 不会丢弃任何错误。我是否不允许为表定义更多连接?

4

1 回答 1

0

你的计划是......不是真的正确。试试这个

  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
于 2012-12-28T16:02:45.770 回答