I have a Doctrine_Collection
object that was created with code that looks something like.
$collection = Doctrine_Query::create()
->from('FooBazBar')
->where('widget_id = ?',$some_var)
->execute();
Short of writing it down somewhere, is it possible to to retrieve the where clause that was used to create the开发者_Python百科 collection?
That is, I want to be able to so something like
$collection->getWhereClauses(); //fake method
And get back the where clause in some form.
A definitive "no, this isn't exposed via the API" with an explanation is a perfectly reasonable answer here.
No, this isn't exposed via the API.
More seriously, you can't retrieve the query that generated the Doctrine_Collection. The easy way to do this is to create a method in your table, like :
//FooTable.php
public function findByWidgetQuery()
{
return $this->createQuery('foo')
->where('foo.baz = ?', 'bar');
}
And then you can use getDqlPart() like this :
$where = Doctrine_Core::getTable('Foo')
->findByWidgetQuery()
->getDqlPart('where');
That should give you an array like this one :
array(2) { [0] => string(8) 'widget = ?' [1] => string(10) 'widget = ?' }
Note that it doesn't return the actual value passed to the where() clause. To do this you need to use Doctrine_Query::getParams() or Doctrine_Query::getFlattenedParams()
You can find everything in the Doctrine API.
getSqlQuery() looks to be the method you're after...
http://www.doctrine-project.org/documentation/manual/1_0/en/dql-doctrine-query-language:debugging-queries
精彩评论