2012-12-28 67 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