0

I have the following query and I want the first result to be hydrated. This is what I tried:

$builder = $dm->createAggregationBuilder(\Documents\Jobs::class);
$builder
    ->facet()
        ->field('carpenterJobs')
        ->pipeline(
            $dm->createAggregationBuilder(\Documents\Jobs::class)
                ->hydrate($this->getEntityName(\Documents\Jobs::class))
                ->match()
                ->field('name')
                ->equals('carpenter');
        )
        ->field('cleanerJobs')
        ->pipeline(
            $dm->createAggregationBuilder(\Documents\Jobs::class)
                ->match()
                ->field('name')
                ->equals('cleaner');
        )
;

But when I execute this, the results are not hydrated. Below is the Jobs entity:

/**
 * @QueryResultDocument
 * @Document(repositoryClass="...")
 */
class Jobs
{
    /**
     * @Id
     */
    private $id;

    /**
     * @Field(type="string")
     * @Index(unique=true, order="asc")
     */
    private $name;

    ...
}

I also tried to hydrate the $builder but it returns an error saying Undefined index: _id. Executing the 'carpenterJobs' query by itself, without being inside a faucet, I can return hydrated results.

Lucas Borges
  • 140
  • 2
  • 13
  • This prolly is not a culprit, but using same class for both `@Document` and `@QueryResultDocument` is not supported and can work in funky ways. – malarzm Nov 28 '18 at 20:59
  • Also please take a look at https://github.com/doctrine/mongodb-odm/issues/1900 as there were lately issues with `facet` and hydration, but I don't know much about that in particular :) – malarzm Nov 28 '18 at 22:12

0 Answers0