Doctrine\ORM\EntityManager::refresh PHP Method

refresh() public method

Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted.
public refresh ( object $entity )
$entity object The entity to refresh.
    public function refresh($entity)
    {
        if ( ! is_object($entity)) {
            throw new \InvalidArgumentException(gettype($entity));
        }
        $this->errorIfClosed();
        $this->unitOfWork->refresh($entity);
    }

Usage Example

コード例 #1
0
ファイル: Translatable.php プロジェクト: ymarillet/sknife
 /**
  * Refreshes an entity with real translations
  * @param $entity
  * @param $language
  *
  * @author Yohann Marillet
  */
 public function refreshEntity($entity, $language)
 {
     $translatableProperties = $this->getTranslatableProperties($entity);
     $setLocaleMethod = $translatableProperties['setLocaleMethod'];
     $entity->{$setLocaleMethod}($language);
     $this->em->refresh($entity);
     if ($this->defaultLocale != $language) {
         if (false !== $translatableProperties['usePersonalTranslations']) {
             /** @var HasTranslations $entity */
             $allTranslations = $entity->getTranslations();
             $translations = [];
             /** @var AbstractPersonalTranslation $translationEntity */
             foreach ($allTranslations as $translationEntity) {
                 if (!isset($translations[$translationEntity->getLocale()])) {
                     $translations[$translationEntity->getLocale()] = [];
                 }
                 $translations[$translationEntity->getLocale()][$translationEntity->getField()] = $translationEntity->getContent();
             }
         } else {
             $translations = $this->getRepository()->findTranslations($entity);
         }
         if (!isset($translations[$language])) {
             $translations[$language] = $translatableProperties['fields'];
         }
         foreach ($translations[$language] as $field => $value) {
             $setter = Strings::toSetter($field);
             $entity->{$setter}($value);
         }
     }
 }
All Usage Examples Of Doctrine\ORM\EntityManager::refresh