Symfony 1.4 чтение отношения 1: русская доктрина - PullRequest
1 голос
/ 31 января 2012

Я хочу получить отношения с двумя таблицами.

Это мой 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 "collection

И у меня есть этот код:

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"


}

Ошибка:

открытая функция filterGet (Doctrine_Record $ record, $ name)

{

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

}

}

Кто-то знает, что не запускается?

Спасибо

С уважением

Ответы [ 2 ]

1 голос
/ 19 февраля 2012

То, как вы называете свой ForeignAlias ​​"Opcions_FK" заглавными буквами ("K") и подчеркиванием, может ввести в заблуждение доктрину. Попробуйте получить доступ непосредственно к свойству Opcions_FK вашей Oferta:

foreach ($ofertes as $oferta) { 

   echo $oferta->getId();

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

       echo $opcions->getOfertaId();

   } 

}
0 голосов
/ 02 февраля 2012

@ method Doctrine_Collection getOpcionsFK () Возвращает текущую запись "Opcions_FK" collection

Попытка:

foreach ($ofertes as $oferta) { 

  echo $oferta->getId();

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

       echo $options-> getOfertaId();
    } 
}
...