2012-01-31 99 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(); 
    } 
}