/** * Set the proxies attribute on a freshly stored entity * * @param \Analogue\ORM\Entity */ protected function setProxies($entity) { if (!$this->entityMap->relationsParsed()) { $initializer = new MapInitializer($this->mapper->getEntityMap()); $initializer->splitRelationsTypes($entity); } $attributes = $entity->getEntityAttributes(); $singleRelations = $this->entityMap->getSingleRelationships(); $manyRelations = $this->entityMap->getManyRelationships(); $proxies = []; foreach ($this->entityMap->getRelationships() as $relation) { if (!array_key_exists($relation, $attributes) || is_null($attributes[$relation])) { if (in_array($relation, $singleRelations)) { $proxies[$relation] = new EntityProxy($entity, $relation); } if (in_array($relation, $manyRelations)) { $proxies[$relation] = new CollectionProxy($entity, $relation); } } } foreach ($proxies as $key => $value) { $entity->setEntityAttribute($key, $value); } }
/** * Deduce the relationships that will be lazy loaded from the eagerLoads array * * @return array */ protected function prepareLazyLoading() { $entityMap = $this->entityMap; if (!$entityMap->relationsParsed()) { $initializer = new MapInitializer($entityMap); $initializer->splitRelationsTypes($this->mapper->newInstance()); } $singleRelations = $entityMap->getSingleRelationships(); $manyRelations = $entityMap->getManyRelationships(); $allRelations = array_merge($manyRelations, $singleRelations); return array_diff($allRelations, $this->eagerLoads); }