DDC-1323: Join-Table with Metadata Hydrator: no results on non existing Metadata #1938

Closed
doctrinebot opened this Issue Aug 7, 2011 · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user slam:

Assume you have:

namespace MyEntity;

class User
{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    private $id;

    /****
     * @OneToMany(targetEntity="UserImages", mappedBy="user")
     */
    protected $images;
}

class UserImages
{
    /****
     * @Id
     * @JoinColumn(name="user_id")
     * @ManyToOne(targetEntity="User", inversedBy="images")
     */
    private $user;

    /****
     * @Id
     * @JoinColumn(name="image_id")
     * @OneToOne(targetEntity="Image")
     */
    private $image;

    /****
     * @Column(name="sort_number", type="integer", columnDefinition="int(10) unsigned DEFAULT NULL")
     */
    protected $sortNumber;
}

class Image
{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    private $id;
}

and now you have on the database:

||user_id||
|1|

||image_id||
|1|

||userid||image_id||sortnumber||
|1|1|NULL|

This is a legitimate situation.

Now, if you dqlQuery:

SELECT u, uImages, uImagesFile
FROM MyEntity\User u
    LEFT JOIN u.images uImages
    LEFT JOIN uImages.file uImagesFile

You will obtain, with HYDRATE_SCALAR:

Array
(
    [0] => Array
        (
            [u_id] => 1
            [uImages_sortNumber] =>
            [uImagesFile_id] => 1
        )
)

But, due to the AbstractHydrator::*gatherRowData that do not fill $nonemptyComponents with the key uImages, because the only filled keys are metaColumns, HYDRATE_OBJECT and HYDRATE*ARRAY will fail:

Array
(
    [0] => MyEntity\User
        (
            [id] => 1
            [images] => Array
                (
                )
        )
)
@doctrinebot

Issue was closed with resolution "Duplicate"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment