1

I want obtain the relations with two tables.

This is my 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}

The are this method: * @method Doctrine_Collection getOpcionsFK() Returns the current record's "Opcions_FK" collection

And i have this code:

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"


}

The error:

public function filterGet(Doctrine_Record $record, $name)

{

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

}

}

Someone know what don't runs it?

Thanks

Regards

4

2 回答 2

1

The way you name your foreignAlias "Opcions_FK" with uppercase ("K") and underscore may confuse Doctrine. Try to access directly to the property Opcions_FK of your Oferta:

foreach ($ofertes as $oferta) { 

   echo $oferta->getId();

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

       echo $opcions->getOfertaId();

   } 

}
于 2012-02-18T22:58:37.263 回答
0

@method Doctrine_Collection getOpcionsFK() Returns the current record's "Opcions_FK" collection

Try:

foreach ($ofertes as $oferta) { 

  echo $oferta->getId();

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

       echo $options-> getOfertaId();
    } 
}
于 2012-02-02T14:43:25.320 回答