views:

428

answers:

2

I'm using Doctrine, a PHP ORM. I have created a Doctrine Query, and I need more control. So I've started to use the ->andWhere(...) methods to add new where clauses. However I need to do a subquery based on another table, like so:

$query->andWhere("id in (SELECT id from other_table where value = ?)", $myvar);

The above doesn't work. However there is no Doctrine class for other_table, and doctrine keeps trying to load the file other_file.php. I have figured out that it is interpreting this as DQL (right?). Is there someway I can tell Doctrine to not interpret this as DQL, so that I can just use raw SQL?

I know I could use Doctrine_RawSql, but that would involve rewriting all of this query. It would be nice if there was a halfway house.

+2  A: 

Even if being able to do this kind of thing (i.e. usings DB tables that are not mapped to a Doctrine class, and using pure-raw-SQL), I don't think it's possible with Doctrine 1.x

Maybe with Doctrine 2.0 -- which is announced for the end of this year... Which is not soon ^^

Pascal MARTIN
+2  A: 

Unfortunately with Doctrine 1.x it is not possible to do this, even using RawSql.

All RawSql queries require that every table selected be mapped to a 'Component', which is really a Doctrine_Record class.

You might be better served adding a class for that other table, even if it's stupidly simple and never used anywhere else.

Otherwise, you'll have to drop to raw PDO using:

$dbh = Doctrine_Manager::connection()->getDbh();

See Doctrine_RawSql

hobodave
Thanks for the info.I like the general idea of Doctrine and other orm, but its performance hit always concerns me.
Jay Zeng
+1 excellent solution!
jspcal
@jspcal: Thanks, I thought you had it out for me :P
hobodave