Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1323

Join-Table with Metadata Hydrator: no results on non existing Metadata

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      All

      Description

      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
      user_id image_id sort_number
      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
      				(
      				)
      		)
      )
      

        Activity

        Hide
        Benjamin Eberlei added a comment -
        Show
        Benjamin Eberlei added a comment - This was fixed in http://www.doctrine-project.org/jira/browse/DDC-1515

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Slam
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: