#5889·orm

"indexBy" configuration on associations is not respected by L2C

Author: orfinCreated Jun 20, 2016Updated Sep 30, 2026
LabelsBug

Hi,

when using indexBy on OneToMany association, returned collection is not indexed by given field.

  • getTranslations with 2ndlevel: [0 => Translation, 1 => Translation]
  • getTranslations without 2ndlevel: ['en' => Translation, 'pl' => Translation]

Sample mapping:

    /**
     * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="cms")
     * 
     * @ORM\OneToMany(targetEntity="Translation", mappedBy="page", cascade={"persist", "remove"}, indexBy="language", orphanRemoval=true)
     */
    protected $translations;


    /**
     * Get translations
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTranslations()
    {
        return $this->translations;
    }