Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-3399: indexBy expects db field names insteadof model property names #4203

Open
doctrinebot opened this issue Nov 19, 2014 · 1 comment
Open
Assignees

Comments

@doctrinebot
Copy link

Jira issue originally created by user backbone:

The following example does work:

/****
 * @ORM\Entity
 */
class Order {

    use IDTrait;

    /****
     * @ORM\OneToMany(
     *      targetEntity="OrderCategory",
     *      mappedBy="order",
     *      indexBy="my*category*id",
     *      fetch="EAGER",
     *      cascade={"all"},
     *      orphanRemoval=true
     * )
     * @var Collection
     */
    private $categories;

}

/****
 * @ORM\Entity
 */
class OrderCategory {

    /****
     * @ORM\ManyToOne(targetEntity="Order", inversedBy="categories")
     * @ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")
     * @ORM\Id
     * @var Order
     */
    private $order;

    /****
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="my*category*id", referencedColumnName="id", onDelete="RESTRICT")
     * @ORM\Id
     * @var Category
     */
    private $category;

}

If you use indexBy="category", it does not work. Why are the object property names used for referencing in most of the mapping, but for indexBy you have to use the db field name? It is nowhere mentioned in the docs.
I didnt test this with non-association properties as indexBy.

@SlKelevro
Copy link

I wonder how did this go completely unnoticed for 5 years, at least in the docs. It now even raises issues with Symfony (starting with 4.4.2 for default configurations), because SF also assumes indexBy value is a entity field, tries to fetch its metadata and of course fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants