0

Here is the schema of two tables that I am querying in doctrine.

I have two tables in my schema called taxonomy and lesson, which have a many to one relation [should really be one to one, but that's how it has been encoded]. My query is encoded in TaxonomyTable.class.php like this:

 $this->createQuery('t.*, l.lid')
      ->innerJoin('t.Lesson l')
      ->where('t.section = ?','specific_section');

The query executes as it should, the challenge really is accessing lesson lid. Assuming the query is executed and stored in a variable $TaxonomyResults ; From prior posts, I understand that it can be done like this:

foreach($TaxonomyResults as $TaxonomyResult)
{
   echo $TaxonomyResult->getLesson()->getLid();
}

But simply put, this does not work for me and I am not sure why. The error that renders across my screen is:

'Doctrine_Collection' does not have a method 'getLid'.

What do you think I am doing wrong here?

j0k
  • 22,600
  • 28
  • 79
  • 90
user1020069
  • 1,540
  • 7
  • 24
  • 41

1 Answers1

2

I can't see your schema.

I guess Taxonomy has a one to many relation with Lesson(Taxonomy is one).

So a Taxonomy object can have many Lessons,

and $TaxonomyResult->getLesson() should return Lesson objects (Doctrine_Collection), not a Lesson object.

You can get your lesson object like array:

$lessons = $TaxonomyResult->getLesson();

echo $lessons[0]->getLid(); 
j0k
  • 22,600
  • 28
  • 79
  • 90
Filix_suo
  • 37
  • 4
  • That's what I was thinking but I wanted to see his schema.yml first – j0k Aug 10 '12 at 10:10
  • that should be technically correct...what I was missing out was that it is a one to many relation and returned a collection, hence a foreach loop was required to iterate through the lesson object and access the specific methods – user1020069 Aug 10 '12 at 18:31