/** * Test removing object when FK is part of the composite PK */ public function testRemove_CompositePK() { BookReaderQuery::create()->deleteAll(); BookQuery::create()->deleteAll(); BookOpinionQuery::create()->deleteAll(); $br = new BookReader(); $br->setName("TestReader"); $br->save(); $b = new Book(); $b->setTitle("TestBook"); $b->setISBN("XX-XX-XX-XX"); $b->save(); $op = new BookOpinion(); $op->setBookReader($br); $op->setBook($b); $op->setRating(10); $op->setRecommendToFriend(true); $op->save(); $this->assertEquals(1, BookReaderQuery::create()->count(), '1 BookReader'); $this->assertEquals(1, BookQuery::create()->count(), '1 Book'); $this->assertEquals(1, BookOpinionQuery::create()->count(), '1 BookOpinion'); // make sure everything is loaded correctly (and their relation too) $br->reload(true); $b->reload(true); $op->reload(true); $br->getBookOpinions(); // load the relation $b->removeBookOpinion($op); $b->save(); // the Book knows that there is no longer an opinion $this->assertEquals(0, count($b->getBookOpinions()), 'Book knows there is no opinion'); // but not the BookReader $this->assertEquals(1, count($br->getBookOpinions()), 'BookReader still thinks it has 1 opinion'); $br->reload(true); // with relations $this->assertEquals(0, count($br->getBookOpinions()), 'BookReader now knows the opinion is gone'); $this->assertEquals(1, BookReaderQuery::create()->count(), '1 BookReader'); $this->assertEquals(1, BookQuery::create()->count(), '1 Book'); $this->assertEquals(0, BookOpinionQuery::create()->count(), '0 BookOpinion'); }
public function testFilterByRefFkCompositeKey() { BookstoreDataPopulator::depopulate(); BookstoreDataPopulator::populate(); BookstoreDataPopulator::populateOpinionFavorite(); // prepare the test data $testOpinion = BookOpinionQuery::create()->innerJoin('BookOpinion.ReaderFavorite')->findOne(); $testFavorite = $testOpinion->getReaderFavorite(); $opinion = BookOpinionQuery::create()->filterByReaderFavorite($testFavorite)->findOne(); $this->assertEquals($testOpinion, $opinion, 'Generated query handles filterByRefFk() methods correctly for composite fkeys'); }