Partial object children in cache #7180

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

Originally created by @duzenko on GitHub (Jul 11, 2023).

Bug Report

Q A
BC Break no
Version 2.8

Summary

Partial objects break object caching

Current behavior

Incomplete joined objects from partial selects save to cache and later are reused without actual data fetch

How to reproduce

Partial select with join. In this case 'lc.auction la' is the no-data object that is saved to cache

		$condition = $e->andX();
		$condition->add( $e->eq( 'la.user', $loaneeId ) );
		$condition->add( $e->in( 'lc.status', [ LoanContract::STATUS_inPreparation, LoanContract::STATUS_legal, LoanContract::STATUS_caseExternal, LoanContract::STATUS_caseInternal ] ) );

		$qb = $this->createQueryBuilder();
		$qb
				->select( 'partial lc.{id}, partial lr.{id}' )
				->from( LoanContract::class, 'lc' )
				->join( 'lc.auction', 'la' )
				->join( 'lc.loaner', 'lr' )
				->where( $condition );

		$q = $qb->getQuery();
		$contracts = $q->getResult();

Later in the same PHP call, but very different class I try to load the auction

		return $this->getRepository()->findOneBy( [ 'extendedWith' => $this->getEntity()->getId() ] );

The auction itself loads OK, but its nested contracts collection only has id's, all other fields are null.
Auction and contracts link to each other via a one-to-many and many-to-one relations.
There may be a bug in the code that checks the 'initialized' state of the partial contract entity that prevents it to load the second time.
So either prevent the auction entity from saving to cache, or make the partial contract entity to reload on next fetch.

Expected behavior

The partial objects do not save to cache and are fully loaded on subsequent requests

Originally created by @duzenko on GitHub (Jul 11, 2023). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.8 #### Summary Partial objects break object caching #### Current behavior Incomplete joined objects from partial selects save to cache and later are reused without actual data fetch #### How to reproduce Partial select with join. In this case 'lc.auction la' is the no-data object that is saved to cache ``` $condition = $e->andX(); $condition->add( $e->eq( 'la.user', $loaneeId ) ); $condition->add( $e->in( 'lc.status', [ LoanContract::STATUS_inPreparation, LoanContract::STATUS_legal, LoanContract::STATUS_caseExternal, LoanContract::STATUS_caseInternal ] ) ); $qb = $this->createQueryBuilder(); $qb ->select( 'partial lc.{id}, partial lr.{id}' ) ->from( LoanContract::class, 'lc' ) ->join( 'lc.auction', 'la' ) ->join( 'lc.loaner', 'lr' ) ->where( $condition ); $q = $qb->getQuery(); $contracts = $q->getResult(); ``` Later in the same PHP call, but very different class I try to load the auction ``` return $this->getRepository()->findOneBy( [ 'extendedWith' => $this->getEntity()->getId() ] ); ``` The auction itself loads OK, but its nested contracts collection only has id's, all other fields are null. Auction and contracts link to each other via a one-to-many and many-to-one relations. There may be a bug in the code that checks the 'initialized' state of the partial contract entity that prevents it to load the second time. So either prevent the auction entity from saving to cache, or make the partial contract entity to reload on next fetch. #### Expected behavior The partial objects do not save to cache and are fully loaded on subsequent requests
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7180