0

I have a query that reads like this:

$fields = Doctrine_Core::getTable('model_1')->findByColumnId($id); 

took a var_dump on fields, and it retrieves data as it should ;

next up, I do this

foreach($fields as $field)
{
 $newerFields[$field->getColumnId()] =
 Doctrine_Core::getTable('model2')->findByColumn2Id($field->getColumnId());
}

I take a var_dump on each $newerFields[$field] and it does yield the result as it should. Next up I try and do this:

foreach($newerFields as $newerField)
{
 echo  $newerField->getColumn3();
}

But this spits out: Call to undefined method Doctrine_Collection::getColumn3() in actions.class.php on line 69

I am not able to wrap my head around this and am flustered thinking on how to get it done. Can anyone spot the trouble for me?

user1020069
  • 1,540
  • 7
  • 24
  • 41

1 Answers1

1

Your findByColumn2Id returns a Doctrine_Collection because findBy always returns a collection (if you don't define it in the table file) even if there is only one result. If you want to retrieve one result, use findOneBy instead.

Otherwise, you will have to loop on newerFields childs to retrieve data:

// array of Doctrine_Collection
foreach($newerFields as $newerFieldCollection)
{
  foreach($newerFieldCollection as $newerField)
  {
    echo $newerField->getColumn3();
  }
}
j0k
  • 22,600
  • 28
  • 79
  • 90
  • Thanks, I figured this out by myself and looping it is the solution since I am looking at a collection of records. – user1020069 Apr 06 '12 at 17:30