Schema validator doesn't report invalid indexBy configuration. #7421

Open
opened 2026-01-22 15:51:32 +01:00 by admin · 0 comments
Owner

Originally created by @janklan on GitHub (Sep 23, 2024).

Bug Report

Q A
BC Break no
Version Tested on 2.x and 3.x

Reproducer

https://github.com/janklan/doctrine-bug-11608. Follow the instructions in README.md to see the bug in action.

A detail of what's happening

  1. In my reproducer, the Plan::$subscription collection uses custom indexBy to allow fetching a Subscription using a Customer ID when known.
  2. The value of indexBy is deceiving because it matches the name of the property but not the name of the DB column
  3. As a result, Doctrine fails to set the collection index, falling back to numeric indexes as if the indexBy wasn't used.

Consequence

  1. Hard-to-debug errors when using Collection methods working with the keys

What's wrong

  1. I expected bin/console doctrine:schema:validate to pick up on this misconfiguration

I reckon this one is quite relevant https://github.com/doctrine/orm/issues/4203

Originally created by @janklan on GitHub (Sep 23, 2024). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | Tested on 2.x and 3.x #### Reproducer https://github.com/janklan/doctrine-bug-11608. Follow the instructions in README.md to see the bug in action. #### A detail of what's happening 1. In my reproducer, the `Plan::$subscription` collection uses custom `indexBy` to allow fetching a `Subscription` using a Customer ID when known. 1. The value of `indexBy` is deceiving because it matches the name of the property but not the name of the DB column 1. As a result, Doctrine fails to set the collection index, falling back to numeric indexes as if the `indexBy` wasn't used. #### Consequence 1. Hard-to-debug errors when using Collection methods working with the keys #### What's wrong 1. I expected `bin/console doctrine:schema:validate` to pick up on this misconfiguration #### Related issues I reckon this one is quite relevant https://github.com/doctrine/orm/issues/4203
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7421