Search code examples
phpdoctrinesymfony-1.4doctrine-query

symfony 1.4 reading relation 1:n doctrine


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


Solution

  • 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();
    
       } 
    
    }