doctrine / doctrine/DoctrineBundle
Identity map, another object of class was already present for the same ID
- Dominant language
- PHP
- Stars
- 4.8k
- Forks
- 482
- Avg merge
- 1h 51m
- Merged PRs (30d)
- 3
Description
### Bug Report
| Q | A
|-------------------------------------------- | ------
| Version | ^3.1
| Previous Version if the bug is a regression | ^2.8
Another doctrine packages:
```
"doctrine/doctrine-bundle": "^3.1",
"doctrine/doctrine-migrations-bundle": "^4.0",
"doctrine/orm": "^3.3",
```
```
"symfony": "7.4"
"php": "8.5.0"
```
Before update to 3.1 - works fine
#### Summary
```
Wallet
#[ORM\ManyToOne(targetEntity: Currency::class, inversedBy: 'wallets')]
#[ORM\JoinColumn(name: 'currency_id', referencedColumnName: 'id', nullable: false)]
private Currency $currency;
```
```
Currency
/**
* @var Collection
*/
#[ORM\OneToMany(targetEntity: Wallet::class, mappedBy: 'currency')]
private Collection $wallets;
```
Uses simple query to get all entities.
```
$this->createQueryBuilder('wallet');
```
#### Current behavior
When the cache does not exist, opening the page causes this error only for these relations in twig.
When use dump in controller - no error.
After the cache is created, everything works fine.
#### Expected behavior
no error
#### How to reproduce
not sure how reproduce and why this error show only for one entity relationship.
Contributor guide
Research direction
Start by reducing the Wallet/Currency mappings and the simple createQueryBuilder('wallet') query to a minimal reproduction. Compare the first page load with an empty cache against the controller dump and the later warm-cache behavior, focusing on Twig access to the relation. Done means the cold-cache page load no longer raises the identity-map error and the regression is covered by a reproducible case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100