2012-01-31 96 views
1

我想獲得與兩個表的關係。symfony 1.4閱讀關係1:n教條

這是我的schema.yml

Oferta: 
    columns: 
    titol: { type: string(50), notnull: true } 
    sub_titol: { type: text } 
    data_inici: { type: date } 
    data_fi: { type: date } 

Opcions: 
    columns: 
    oferta_id: { type: integer, notnull: true } 
    descripco: { type: string(150), notnull: true } 
    preu: { type: string(20), notnull: flase } 
    relations: 
    Oferta: {onDelete: CASCADE, local: oferta_id, foreign: id, foreignAlias: Opcions_FK} 

的是這種方法:* @method Doctrine_Collection getOpcionsFK()返回當前記錄的 「Opcions_FK」 收集

,我有這樣的代碼:

foreach ($ofertes as $oferta) { 


    echo $oferta->getId(); 
    $opcions = new Opcions(); 
    $opcions = $oferta->getOpcionsFK(); //this line do a error Unknown record property/related component "opcions_fk" on "Oferta" 


} 

該錯誤:

public function filterGet(D octrine_Record $紀錄,$名)

{ 

    throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property/related component "%s" on "%s"', $name, get_class($record))); 

} 

}

有人知道什麼是不運行它?

感謝

問候

+0

您可以發佈完整的錯誤嗎? Gràcies;) – 2012-01-31 18:23:53

+0

另請參見:getOpcionsFK自動生成或自定義的方法?如果由yoursef定義,你能顯示它嗎?自動生成 – 2012-01-31 18:28:14

+0

。謝謝 – 2012-01-31 18:30:11

回答

1

你的名字的方式你foreignAlias「Opcions_FK」帶有大寫字母(「 K「)和下劃線可能會混淆主義。嘗試直接訪問您的Oferta的Opcions_FK:

foreach ($ofertes as $oferta) { 

    echo $oferta->getId(); 

    foreach($oferta->Opcions_FK as $opcions){ 

     echo $opcions->getOfertaId(); 

    } 

} 
0

@method Doctrine_Collection getOpcionsFK()返回當前記錄的 「Opcions_FK」 收集

嘗試:

foreach ($ofertes as $oferta) { 

    echo $oferta->getId(); 

    foreach($oferta->getOpcionsFK() as $options){ 

     echo $options-> getOfertaId(); 
    } 
}