开发者

How to Hydrate custom query in Symfony/Doctrine

After performing a custom query using

$DBH = Doctrine_Manager::getInstance()->connection()->getDbh();
$PDO = $DBH->prepare("mysql query");
$PDO->execute();

How do I return model objects instead of record arrays?

开发者_高级运维

EDIT I got mine working by using something like this: $data_object = doctrine_core::getTable('table_name')->find('id_from_raw_SQL'). Easy as pie! And thanks to Dan for the hint.


I don't think you can automatically with a raw SQL query. You could always write your own hydrate method that creates the objects from the results.

If you want Doctrine to do it, you have to write at least the SELECT portion of the query with certain syntax to use Doctrine_RawSql and get hydrated objects:

http://www.doctrine-project.org/documentation/manual/1_2/en/native-sql

http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_rawsql.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜