Serge Velikan
Serge Velikan

Reputation: 1181

Doctrine MongoDB reference hydrate false and prime

Good evening everyone.

Please, help me with my Doctrine/Mongo problem.

I have a document, which has a ReferenceOne to another document and ReferenceMany to other document.

So I need to run one query to get full document tree for my first document as associative array.

I'm trying to do it like that:

return $this->createQueryBuilder()
        ->field('category')->references($category)
        ->field('vendor')->prime()
        ->field('chars')->prime()
        ->hydrate(false)
        ->getQuery()
        ->execute();

But as result i get array like this:

Array
(
[0] => Array
    (
        [_id] => MongoId Object
            (
                [$id] => 52e374c21c83735f098b4567
            )

        [category] => Array
            (
                [$ref] => Category
                [$id] => MongoId Object
                    (
                        [$id] => 52dc56eb1c837345098b4567
                    )

                [$db] => doctrine
            )

        [chars] => Array
            (
                [0] => Array
                    (
                        [$ref] => ProductChar
                        [$id] => MongoId Object
                            (
                                [$id] => 52e374c21c83735f098b4568
                            )

                        [$db] => doctrine
                    )

                [1] => Array
                    (
                        [$ref] => ProductChar
                        [$id] => MongoId Object
                            (
                                [$id] => 52e374c21c83735f098b4569
                            )

                        [$db] => doctrine
                    )

            )

        [href] => href-test
        [price] => 500
        [title] => test
        [vendor] => Array
            (
                [$ref] => Vendor
                [$id] => MongoId Object
                    (
                        [$id] => 52e170571c837360098b4567
                    )

                [$db] => doctrine
            )

    )

)

But I need not just only IDs of referenced documents, but all values as well.

So now I don't know how to retrieve whole document array tree.

Thank you all in advance!

Upvotes: 0

Views: 2679

Answers (1)

jmikola
jmikola

Reputation: 6922

Priming requires hydration. If you investigate Query::execute(), you'll see that it abruptly returns if hydration is disabled. The primer handling would occur later on in that method if hydration was enabled. I've created #800 to ensure we document this limitation, since it is not discussed in Priming References. It may be possible to implement support for priming in the future, but we don't have any present plans for it.

Upvotes: 3

Related Questions