2013-06-03 14 views
0

對不起,對於這個非常具體的問題,我幾次遇到這個問題,我的解決方案(不是最好的是重命名錶和做更多的東西),顯然它不是一個真正的解決方案,這次我再次陷入同樣的​​情況,與我甚至沒有操縱過的桌子,我想知道是否有人以前遇到同樣的問題。如何解決symfony 1.4使用原則的「列未找到」衝突?

在symfony 1.4和理論工作,我從一個不相關的表的查詢得到這個錯誤

Column not found: 1054 Unknown column 'o.training_id' in 'field list' 

我真的不知道什麼是錯,在我的schema.yml我有這樣的事情

OhrmTraining: 
    connection: doctrine 
    tableName: training 
    columns: 
    id_training: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    name: 
     type: string(60) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
TrainingDetail: 
    connection: doctrine 
    tableName: training_detail 
    columns: 
    id_training_detail: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    training: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    relations: 
    OhrmTraining: 
    local: training 
    foreign: id_training 
    type: one 

與其他表詳細相關

這樣

TrainingDetail: 
    connection: doctrine 
    tableName: training_detail 
    columns: 
    id_training_deetail: 
    type: integer(4) 
    fixed: false 
    unsigned: false 
    primary: true 
    autoincrement: true 
    training: 
    type: integer(4) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
relations: 
    Training: 
    local: training 
    foreign: id_training 
    type: one 

,我認爲它是正確的,但是在我的學說/基/ BaseTraining.class我在結束這樣的事情(培訓)

public function setUp() 
{ 
    parent::setUp(); 
    $this->hasMany('TrainingDetail', array(
     'local' => 'id', <--- this should be the id_training_detail?? 
     'foreign' => 'training_id')); <--- this should be training? 

我不知道他們爲什麼是這樣的,或者如果他們應該是這樣的...有人能幫助我嗎?

我改變了他們對

public function setUp() 
{ 
    parent::setUp(); 
    $this->hasMany('TrainingDetail', array(
     'local' => 'id_training', 
     'foreign' => 'training')); 

不過,我得到的錯誤,如果我做一個重拍車型都將蕩然無存

有沒有簡單的方法來創建在schema.yml文件一個數據庫?

編輯: 拋出異常的查詢是這樣的

$query = Doctrine_Query::create() 
    ->from('Times a') 
    ->where('a.employee_id = ?', $employeeId) 
    ->orderBy('a.start_date ASC'); 
    $results = $query->execute(); 

我的員工的基礎上檢查,並與訓練沒有關係,它與訓練的細節......但不直接與訓練中,我重新創建我的模型10次,還是一樣

+0

我不認爲我可以開始做你的方案的意義,因爲你的條款很混亂。也就是說,你在幾個地方拼寫'訓練'作爲'訓練'。也就是說,在你的關係中,你正在定義'local:training',除了該字段被命名爲'trainning'。也可能有其他錯誤。 – Slickrick12

+0

對不起,真實姓名沒有訓練,其公司有什麼訓練,但我對此案例進行了更改 – jpganz18

+1

仔細檢查整個模式文件的拼寫和縮進。如果縮進是錯誤的學說可能會混淆。 –

回答

2

「不過,我的錯誤,如果我做一個重拍車型都將不復存在」

這是因爲你通過基編輯的設置類,基類ALWAYS當您建立模型時會得到超模。

「有沒有簡單的方法來從數據庫創建schema.yml文件?」

這沒有意義。很明顯,您可以從架構中生成架構文件,否則您不會擁有架構文件。

根據給定的模式文件,關係的位置顯示正確。根據Doctrine's docs

「當指定關係時,只需要在外鍵所在的末端指定關係,當解析模式文件時,它將反映關係並自動構建相反的一端。手動關係的另一端,自動生成將不起作用。「

在構建模型文件時,doctrine將在基類中正確配置setUp方法,因此您不需要這樣做。如果要更改關係,請通過模式文件對其進行更改,然後重建模型文件

我懷疑你所遇到的問題是你如何構建查詢,或者通過DQL或模型引用,因爲您發佈的錯誤:

沒有找到

「列:1054未知列'o.training_id'in'field list'「

- - 編輯 -

基於錯誤,和您的查詢,您可以指定列選擇,試試這個:

$query = Doctrine_Query::create() 
    ->select('a.*') 
    ->from('Times a') 
    ->where('a.employee_id = ?', $employeeId) 
    ->orderBy('a.start_date ASC'); 

$results = $query->execute(); 
+0

謝謝你的回答,不幸的是,查詢是一個簡單的select * from另一個表,甚至沒有關聯,這就是爲什麼這個錯誤是如此奇怪。我不知道現在該做什麼,我不知道數據來自哪裏! – jpganz18

+0

您可以發佈生成查詢的代碼嗎? –

+0

謝謝,我編輯了我的帖子,請你看看?我在那裏發佈了我的查詢。 – jpganz18