php - Identify whether a managed entity needs to be refreshed based on getReference -
let's assume have entity 'application' , 1 of 'application's' attributes category (it doesn't matter of association type).
so when know category id can call like:
$category = $entitymanager->getreference('category', 1); $application->setcategory($category); $entitymanager->flush(); getreference create proxy can set attribute application. , works without additional sql query sent db getting/setting category.
great!
but wait, when try e.g. name category afterwards, do? thought i'd:
$category = $entity->getrepository('category')->find(1); $name = $category->getname(); what's happening don't name error entity cannot found.
i can fight issue explicitly calling:
$entitymanager->refresh($category); now reload category database , can name.
my question is:
is there chance identify whether have reference category or initialized / real proxy one?
because in case, have need access category after retrieving reference , not.
if 'refresh' anytime have unnecessary sql statements executed have avoid performancewise and
$entitymanager->getunitofwork()->getentitystate($category) delivers managed in case.
according this: https://stackoverflow.com/a/26257234/3784145 can check if reference instance of proxy class (doctrine\orm\proxy\proxy) , take action accordingly
Comments
Post a Comment