0
votes

I'm using Doctrine's native query feature according to Doctrine Native Queries.I'm using a stored procedure to retrieve the data I want, and have created an entity for it that acts like a wrapper, let's call this Entity Foo.this Entity has a single one-to-one association field as it's primary key to Entity Bar. However in the stored procedure I do not retrieve Bar's Id field, and that in turn causes not to retrieve the primary key for Foo this will cause Doctrine's Hydrator (Doctrine\ORM\Internal\Hydration\ObjectHydrator) to return a null result instead of the real one, because of line 473 of the ObjectHydrator. is there a way around this except for adding the primary key of Bar to the result of the stored Procedure? (I will test this out and report back)


The Results from trying to add the primary key of Bar Entity:

the mapping metadata for Foo:

#Foo.orm.yml
Symf\TestBundle\Entity\Foo:
    type: entity
    id: 
        bar:
            associationKey: true
    oneToOne:
        bar:
            targetEntity: Symf\TestBundle\Entity\Bar
            joinColumn:
                name: bar_ID
                referencedColumnName: id  

#Bar.orm.yml
Symf\TestBundle\Entity\Bar:
    type: Entity
    id:
        id:
            type: integer
            generator: 
                strategy: IDENTITY

So in my ResultSetMapping instance for mapping the data of the StoredProcedure to Foo Entity I used the following code:

$rsm = new ResultSetMapping();
    $rsm->addEntityResult("Symf\\TestBundle\\Entity\\Foo", 'f')
        ->addMetaResult('f', 'Bar_SQL_column_name_in_stored_procedure', 'bar', true);

the last parameter signifies that this is a primary key of the Foo Entity. But Now I get the following Error:

Undefined index: bar_ID in /path/to/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2532

"bar_ID" is the name of the joinColumn specified in Foo's mapping. This seems like a bug to me, because doctrine should ignore columnNames when using custom ResultSetMappings. is this a bug or am I missing something?

1
It didn't work, even with the primary key of Bar includeduser2268997

1 Answers

0
votes

Solved the Doctrine docs state that the third argument to addMetaResult should be the column name mentioned in the mapping and not the field name