2010-08-18 25 views
1

我知道這必須有一個簡單的答案,但我無法弄清楚。我熱淚盈眶後,希望有人能幫上忙。爲什麼Doctrine ORM不會爲我的1對多模型創建SQL查詢?

這裏是我的陽明型號:

Identity: 
    columns: 
    id: 
     type:   integer(10) 
     primary:  true 
     autoincrement: true 
    username: 
     type:   string(255) 

Profile: 
    columns: 
    id: 
     type:   integer(10) 
     primary:  true 
     autoincrement: true 
    identity_id: 
     type:   integer(10) 
    profiletype_id: 
     type:   integer(10) 
    name: 
     type:   string(255) 
    relations: 
    Identity: 
     local:   identity_id 
     foreign:  id 
     class:   Identity 
     foreignAlias: Profiles 
    Profiletype: 
     local:   profiletype_id 
     foreign:  id 
     class:   Profiletype 
     foreignAlias: Profiles 

Profiletype: 
    columns: 
    id: 
     type:   integer(10) 
     primary:  true 
     autoincrement: true 
    type: 
     type:   string(255) 

正如你可以看到,生成3個表:

身份
- 可以有多個配置文件

檔案
- 有一個身份
- 擁有一個Profiletype

Profiletype
- 可以有多個配置文件

現在,在我的代碼,我可以執行查詢的身份和Profiletype的生成的模型。

例如:

 $q = Doctrine_Query::create() 
      ->select('i.*') 
      ->from('Identity i'); 
     echo $q->getSqlQuery(); 

將工作和生產:

SELECT i.id AS i__id, i.username AS i__username FROM identity i 

然而,當我去跑在配置表的任何查詢,它不會工作。即使是一個簡單的查詢,如

 $q = Doctrine_Query::create() 
      ->select('p.*') 
      ->from('Profile p'); 
     echo $q->getSqlQuery(); 

失敗。我曾嘗試將FROM中的類名更改爲'Profiles'而不是'Profile'。依然沒有。

任何想法我做錯了。

+0

嗯......不能重現你的錯誤。你得到什麼樣的錯誤?我假設你正在使用mysql。你是否嘗試過一個不太詳細的模式定義,即:不要爲你的模型定義id,只爲你的關係定義foreignAlias。應該不重要,但值得一試。 – 2010-08-18 08:25:52

+0

拋出的錯誤將是有用的。在'Base'模型(或其他地方)中是否有可能被調用的自定義代碼? – DrColossos 2010-08-18 16:45:56

+0

@Darragh:是的,我正在使用mysql。嘗試過各種模式。在我的定義中,我通常沒有那麼冗長,但是,考慮到我把頭髮撕掉了,我試圖在模式中完全拼寫出所有的東西。任何其他想法? – 2010-08-18 23:37:15

回答

0

改變每一個可能的變量,並通過我的示範線,由線追蹤後,我來到了一個尷尬的發現:

控制器我打電話學說查詢從被稱爲profile.php。

profile.php

<?php 
class Profile extends Controller { 

    function Profile()  { 
     parent::Controller(); 
    } 

    function index()  { 
     $q = Doctrine_Query::create() 
      ->from('Profile'); 
     echo $q->getSqlQuery(); 
    } 

} 

驢只要我叫控制器別的東西比「個人資料」等,這一切突然工作。例如,命名它docile.php:

docile.php

<?php 
class Docile extends Controller { 

    function Docile()  { 
     parent::Controller(); 
    } 

    function index()  { 
     $q = Doctrine_Query::create() 
      ->from('Profile'); 
     echo $q->getSqlQuery(); 
    } 

} 

'資料' 不會出現在笨保留字(link text)。然而,它確實出現了,你不能從同名的控制器類中調用一個doctrine'table class'。

感謝您的輸入人。希望這可以節省別人類似的麻煩。

相關問題