generate:entities does not translate index associations #5488

Closed
opened 2026-01-22 15:09:00 +01:00 by admin · 1 comment
Owner

Originally created by @bodograumann on GitHub (Mar 31, 2017).

Originally assigned to: @Ocramius on GitHub.

Working with indexed associations explains the usage of the indexBy keyword.
For it to work, the insertion method needs to look as follows:

public function addStock(Stock $stock)
{
    $this->stocks[$stock->getSymbol()] = $stock;
}

Now when executing php bin/console doctrine:generate:entities, the generated code is the same, as if no indexBy clause was used:

public function addStock(Stock $stock)
{
    $this->stocks[] = $stock;
}

Furthermore the getStock method is not generated at all.

I am using the current doctrine/orm v2.5.6

Originally created by @bodograumann on GitHub (Mar 31, 2017). Originally assigned to: @Ocramius on GitHub. [Working with indexed associations](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/working-with-indexed-associations.html) explains the usage of the `indexBy` keyword. For it to work, the insertion method needs to look as follows: public function addStock(Stock $stock) { $this->stocks[$stock->getSymbol()] = $stock; } Now when executing `php bin/console doctrine:generate:entities`, the generated code is the same, as if no `indexBy` clause was used: public function addStock(Stock $stock) { $this->stocks[] = $stock; } Furthermore the `getStock` method is not generated at all. I am using the current doctrine/orm v2.5.6
admin added the Won't FixQuestion labels 2026-01-22 15:09:00 +01:00
admin closed this issue 2026-01-22 15:09:01 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 31, 2017):

Meh, this is a detail that is up to your domain, not to the ORM... It also assumes that you are re-generating all entities, and that the getter exists on the associated entity.

@Ocramius commented on GitHub (Mar 31, 2017): Meh, this is a detail that is up to your domain, not to the ORM... It also assumes that you are re-generating all entities, and that the getter exists on the associated entity.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5488