[DBAL-544] Where's the Query::HYDRATE_BOTH constant? Created: 12/Jun/13  Updated: 22/Dec/13  Resolved: 22/Dec/13

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.3.4
Fix Version/s: 2.5

Type: Bug Priority: Minor
Reporter: Julio Montoya Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
Labels: Query::HYDRATE_BOTH
Environment:

Doctrine 2.3.4 DBAL + ORM, using Silex



 Description   

In the documentation of the the ResultStatement::fetch() function says that we should use the Query::HYDRATE_* constants but that constant does not exist at least not in 2.3.4.

Should I just use PDO::FETCH_BOTH? But if I change the driver to sqlite or whatever is it going to work well?



 Comments   
Comment by Marco Pivetta [ 12/Jun/13 ]

Query constants are defined in AbstractQuery (superclass of the Query class) - see https://github.com/doctrine/doctrine2/blob/2.3.4/lib/Doctrine/ORM/AbstractQuery.php#L45-L60

Comment by Julio Montoya [ 12/Jun/13 ]

Hello Marco! Thanks for your fast answer!
Some comments: The constant HYDRATE_BOTH doesn't exist, at least not with that name. Documentation should be updated too.
Another thing I'm obliged to use ORM to call a constant in DBAL? Not a problem for me because I need both

Comment by Marco Pivetta [ 12/Jun/13 ]

Sorry, confused this one as an ORM issue.

Comment by Marco Pivetta [ 12/Jun/13 ]

Checked briefly - you should indeed use the `PDO::FETCH_*` constants.

Can you link the document that contains the imprecision?

Comment by Julio Montoya [ 12/Jun/13 ]

This is the documentation in the fetch(), fetchAll() functions in DBAL:

https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Driver/ResultStatement.php#L61

For example, if I want to fetch an Object what should I use 1. or 2. ? I don't know if this have some implications in other drivers.

1. $statement->fetch(\Doctrine\ORM\Query::HYDRATE_OBJECT);
2. $statement->fetch(PDO::FETCH_OBJ);

An update to the documentation will be fine too:

http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html#using-prepared-statements

it should be:

fetch($fetchMode)

instead of

fetch($fetchStyle)

with a list of options (constants) ...

Comment by Julio Montoya [ 13/Jun/13 ]

Working in a PR but first we need to define those constants ...

https://github.com/jmontoyaa/dbal/commit/d3a44589cdef6c146592eee2b2bd9f8907dadd1f

Comment by Steve Müller [ 28/Nov/13 ]

I guess this is a Doctrine 1 legacy problem. I was confused by the methods' documentation today, too. I think the documentation was copied from Doctrine 1 code and never updated. You should definitely use PDO_FETCH* constants for this as the drivers rely on this. I will PR a documentation update these days...

Comment by Steve Müller [ 22/Dec/13 ]

Documentation fixed in commit: https://github.com/doctrine/dbal/commit/7fc6b420a296504c56859f67ed1dc16a9a3bbdfe

Generated at Mon Sep 22 14:13:23 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.