Пример #1
0
 /**
  * @see \Oro\Bundle\EntityBundle\Provider\EntityFieldProvider::getRelations
  *
  * @param string $entityName
  * @param bool $withEntityDetails
  * @param bool $applyExclusions
  * @param bool $translate
  * @return array
  */
 public function getRelations($entityName, $withEntityDetails = false, $applyExclusions = true, $translate = true)
 {
     $args = func_get_args();
     $cacheKey = implode(':', $args);
     if (!array_key_exists($cacheKey, $this->relationsCache)) {
         $this->relationsCache[$cacheKey] = $this->fieldProvider->getRelations($entityName, $withEntityDetails, $applyExclusions, $translate);
     }
     return $this->relationsCache[$cacheKey];
 }
Пример #2
0
 /**
  * Finds detached properties in entity and reloads them from UnitOfWork
  *
  * @param object $entity doctrine entity
  * @param int $level maximum nesting level
  */
 public function fixEntityAssociationFields($entity, $level = 0)
 {
     if ($level < 0) {
         return;
     }
     // we should use entityFieldProvider to get relations data to avoid deleted relations in result list
     $relations = $this->entityFieldProvider->getRelations(ClassUtils::getClass($entity));
     if (!$relations) {
         return;
     }
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     foreach ($relations as $associationMapping) {
         $fieldName = $associationMapping['name'];
         $value = $propertyAccessor->getValue($entity, $fieldName);
         if ($value && is_object($value)) {
             if ($value instanceof Collection) {
                 $this->fixCollectionField($value, $level);
             } else {
                 $this->fixEntityField($entity, $fieldName, $value, $level);
             }
         }
     }
 }
 /**
  * @param array $expected
  *
  * @dataProvider relationsExpectedDataProvider
  */
 public function testGetRelations(array $expected)
 {
     $this->prepareWithRelations();
     $result = $this->provider->getRelations('Acme:Test', true);
     $this->assertEquals($expected, $result);
 }