Doctrine: How can I reference an attribute of a model with arrow ('->') notation?

TunnelOfMath

New Member
According to the Doctrine manual I should be able to reference an attribute of a model using either arrow notation (\[code\]$record->myField\[/code\]) or array notation (\[code\]$record['myField']\[/code\]) as long as the model is derived from the \[code\]Record\[/code\] class.I used Doctrine to generate my models from my database, so I have a (generated) \[code\]Recipe\[/code\] class which extends a \[code\]BaseRecipe\[/code\] class which extends \[code\]Doctrine_Record\[/code\]. After instantiating a \[code\]Recipe\[/code\] object I can use the array notation to access its values, but using arrow notation just returns empty values. What am I missing?The BaseRecipe class which was generated by Doctrine has two methods:\[code\]public function setTableDefinition(){ $this->setTableName('rcp_recipe'); $this->hasColumn('recipe_id', 'integer', 4, array( 'type' => 'integer', 'fixed' => 0, 'unsigned' => false, 'primary' => true, 'autoincrement' => true, 'length' => '4', )); ...}public function setUp(){ parent::setUp(); $this->hasMany('RcpTime', array( 'local' => 'time_id', 'foreign' => 'time_id')); ...}\[/code\]And here's how I'm trying to use it:\[code\] $newRecipes = RecipeService::getLatestRecipes(); foreach ($newRecipes as $recipe) { echo($recipe['title']); // prints the expected value echo($recipe->title); // prints empty string }\[/code\]And here's my \[code\]getLatestRecipes\[/code\] method:\[code\]static function getLatestRecipes() { $q = Doctrine_Query::create() ->from('Recipe') ->orderBy('recipe_id desc') ->limit(5); return $q->fetchArray();}\[/code\]
 
Back
Top