views:

57

answers:

2

I's like to do a join between 2 tables on a specific ID. At the moment, I have this DQL:

$q = Doctrine_Query::create()
         ->select('e.*, i.itemName, i.itemtypeId')
         ->from('Model_EventItem e')
         ->leftJoin('Model_Item i ON e.itemId = i.itemId')
         ->where('e.eventitemId = ?', $event->eventId)
         ->orderBy('i.itemName ASC');

The result is empty, although my eventId has a value ... Can you help me please? I there somewhere a tutorial on DQL-joins? I don't get it right with the help of the Doctrine documentation.

Thanks!

PS I have doctrine working in combination with Zend Framework.

A: 
$q = Doctrine_Query::create()
     ->select('e.*, i.itemName, i.itemtypeId')
     ->from('Model_EventItem e, e.Model_Item i')
     ->where('e.eventitemId = ?', $event->eventId)
     ->orderBy('i.itemName ASC');
Tom
There is something wrong zith my relations in the schema ...This error pops up: Message: Unknown relation alias Model_Item
koko
Yep, best to check that. Doctrine models are usually written in camel case rather than with underscores.
Tom
+1  A: 

you need add a relation to the model and join the tables using the relation

$q = Doctrine_Query::create()
     ->select('e.*, i.itemName, i.itemtypeId')
     ->from('Model_EventItem e')
     ->leftJoin('Model_EventItem.Model_Item i')
     ->where('e.eventitemId = ?', $event->eventId)
     ->orderBy('i.itemName ASC');
zolex
Ok, But how can I add a relation between models? I have no idea ... Never done it
koko
you can define relations in the yaml schema or implement them yourself in the setUp-method of the (Base)Model
zolex