public function setRepository(IRepository $repository)
{
if ($this->repository && $this->repository !== $repository) {
$name = get_class($this);
throw new InvalidStateException("Mapper '{$name}' is already attached to repository.");
}
$this->repository = $repository;
$this->collectionCache = (object) null;
}