Symfony 1.4,学说:多连接到一张表 [英] Symfony 1.4, doctrine: multiple join to one table

查看:28
本文介绍了Symfony 1.4,学说:多连接到一张表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案:

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 显示为外键:

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 不会丢弃任何错误.我不能定义更多的表连接吗?

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

推荐答案

你的方案……不太正确.试试这个

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

这篇关于Symfony 1.4,学说:多连接到一张表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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