public function testSetAndClearScope() { $authorRepo = new AuthorRepository(); $count = $authorRepo->scope(function ($query) { $query->where('id', '=', 1); })->reset()->count(); $this->assertTrue($count == count($this->authors)); }
public function testCriteriaStringParameter() { $authorRepository = new AuthorRepository(); $authorRepository->criteria(['WithPostsCriteria']); $this->assertTrue($authorRepository->hasCriteria()); $this->assertTrue($authorRepository->count() == count($this->authors)); $authors = $authorRepository->all(); $this->assertTrue(isset($authors[0]['posts'])); }
public function testCriteriaAndScope() { $authorRepository = new AuthorRepository(); $authorRepository->criteria([WithPostsCriteria::class])->scope(function ($query) { $query->where('id', '>', 1); }); $authors = $authorRepository->all(); $this->assertTrue(count($authors) == 2); $this->assertTrue(isset($authors[0])); $this->assertTrue(isset($authors[0]['posts'])); }
/** * @param bool $full * * @return Publication|false */ public function findSingle($full = false) { $result = parent::findSingle(); if ($result) { $publication = new Publication($result); $repo = new AuthorRepository($this->db); $publication->setAuthors($repo->where('publication_id', '=', $publication->getId())->order('priority', 'ASC')->find()); $repo = new FileRepository($this->db); $publication->setFiles($repo->where('publication_id', '=', $publication->getId())->find()); $repo = new UrlRepository($this->db); $publication->setUrls($repo->where('publication_id', '=', $publication->getId())->find()); if ($full === true) { $repo = new KeywordRepository($this->db); $publication->setKeywords($repo->where('publication_id', '=', $publication->getId())->order('name', 'ASC')->find()); $repo = new CitationRepository($this->db); $publication->setCitations($repo->where('publication_id', '=', $publication->getId())->find()); } return $publication; } else { return false; } }