/** * @return Models\Category */ protected function createCategory() { $cat = new Models\Category(['name' => 'Cat 1']); $cat->save(); $cat2 = new Models\Category(['name' => 'Another Cat']); $cat2->save(); $cat2 = new Models\Category(['name' => 'B. Another cat']); $cat2->save(); $book = new Models\Book(['name' => 'Book 3']); $book->save(); $cat->book()->save($book); $theme = new Models\Theme(['name' => 'Theme 1']); $theme->save(); $cat->themes()->save($theme); return $cat; }
public function test_does_add_required_fields_for_morph_to_relation() { $this->populateDatabase(); $model = new Models\Book(); $query = $model->query()->with('bookable'); $modifier = $this->_getInstance($query, ['fields' => 'name']); $modifier->modify($query); $reqFields = $modifier->addRequiredFields(['name']); $this->assertEquals(3, count($reqFields)); $this->assertContains('bookable_id', $reqFields); $this->assertContains('bookable_type', $reqFields); $this->assertContains('name', $reqFields); $this->assertInstanceOf(Models\Editor::class, $query->find(2)->bookable); }