Reputation: 60759
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.
Upvotes: 1
Views: 1624
Reputation: 29303
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
Upvotes: 3
Reputation: 401142
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 ^^
Upvotes: 2