2012-12-28 39 views
0

方案:的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 

,你可以看到,在User.ID的Task.OWNER_ID和Task.CREATED_ID点 - 不过,只有OWNER_ID显示为外键在实际的SQL表中:

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不会丢失任何错误。我不允许定义更多的表连接吗?

+0

哪里是你的查询,使一个加入? – j0k

+0

无处,Symfony构建了db symfony主义:build --all --no-confirmation – user1929946

回答

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 
+0

嗯我以为UserCreator/UserOwner必须指向一个类 – user1929946