/** * Check for entity existence in the EntityCache * * @return boolean */ public function exists() { if (!$this->hasPrimaryKeyDefined()) { $this->exists = false; } else { $cache = $this->mapper->getEntityCache(); $key = $this->entityMap->getKeyName(); // Check if we have a cache record for the entity // which have to be the case. if ($cache->has($this->entity->getEntityAttribute($key))) { $this->exists = true; } else { $this->exists = false; } } return $this->exists; }
/** * Cache Relation's query result for an entity * * @param Mappable $parent * @param string $relation name of the relation * @param mixed $results results of the relationship's query * * @return void */ public function cacheLoadedRelationResult($parent, $relation, $results, Relationship $relationship) { $keyName = $this->entityMap->getKeyName(); $key = $parent->getEntityAttribute($keyName); if ($results instanceof Mappable) { $this->cacheSingleRelationResult($key, $relation, $results, $relationship); } if ($results instanceof EntityCollection) { $this->cacheManyRelationResults($key, $relation, $results, $relationship); } }