コード例 #1
0
 /**
  * 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');
 }
コード例 #2
0
ファイル: GeneratedObjectTest.php プロジェクト: ratibus/Crew
 /**
  * Test copying when an object has composite primary key.
  * @link http://propel.phpdb.org/trac/ticket/618
  */
 public function testCopy_CompositePK()
 {
     $br = new BookReader();
     $br->setName("TestReader");
     $br->save();
     $br->copy();
     $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();
     $br2 = $br->copy(true);
     $this->assertNull($br2->getId());
     $opinions = $br2->getBookOpinions();
     $this->assertEquals(1, count($opinions), "Expected to have a related BookOpinion after copy()");
     // We DO expect the reader_id to be null
     $this->assertNull($opinions[0]->getReaderId());
     // but we DO NOT expect the book_id to be null
     $this->assertEquals($op->getBookId(), $opinions[0]->getBookId());
 }
コード例 #3
0
 /**
  * @link       http://propel.phpdb.org/trac/ticket/519
  */
 public function testDoDeleteCompositePK()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     ReaderFavoritePeer::doDeleteAll();
     // Create books with IDs 1 to 3
     // Create readers with IDs 1 and 2
     $this->createBookWithId(1);
     $this->createBookWithId(2);
     $this->createBookWithId(3);
     $this->createReaderWithId(1);
     $this->createReaderWithId(2);
     for ($i = 1; $i <= 3; $i++) {
         for ($j = 1; $j <= 2; $j++) {
             $bo = new BookOpinion();
             $bo->setBookId($i);
             $bo->setReaderId($j);
             $bo->save();
             $rf = new ReaderFavorite();
             $rf->setBookId($i);
             $rf->setReaderId($j);
             $rf->save();
         }
     }
     $this->assertEquals(6, ReaderFavoritePeer::doCount(new Criteria()));
     // Now delete 2 of those rows (2 is special in that it is the number of rows
     // being deleted, as well as the number of things in the primary key)
     ReaderFavoritePeer::doDelete(array(array(1, 1), array(2, 2)));
     $this->assertEquals(4, ReaderFavoritePeer::doCount(new Criteria()));
     //Note: these composite PK's are pairs of (BookId, ReaderId)
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2, 1));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1, 2));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3, 1));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3, 2));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(1, 1));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(2, 2));
     //test deletion of a single composite PK
     ReaderFavoritePeer::doDelete(array(3, 1));
     $this->assertEquals(3, ReaderFavoritePeer::doCount(new Criteria()));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2, 1));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1, 2));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3, 2));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(1, 1));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(2, 2));
     $this->assertNull(ReaderFavoritePeer::retrieveByPk(3, 1));
     //test deleting the last three
     ReaderFavoritePeer::doDelete(array(array(2, 1), array(1, 2), array(3, 2)));
     $this->assertEquals(0, ReaderFavoritePeer::doCount(new Criteria()));
 }
コード例 #4
0
 /**
  * Testing foreign keys with multiple referrer columns.
  * @link       http://propel.phpdb.org/trac/ticket/606
  */
 public function testMultiColFk()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     ReaderFavoritePeer::doDeleteAll();
     $b1 = new Book();
     $b1->setTitle("Book1");
     $b1->setISBN("ISBN-1");
     $b1->save();
     $r1 = new BookReader();
     $r1->setName("Me");
     $r1->save();
     $bo1 = new BookOpinion();
     $bo1->setBookId($b1->getId());
     $bo1->setReaderId($r1->getId());
     $bo1->setRating(9);
     $bo1->setRecommendToFriend(true);
     $bo1->save();
     $rf1 = new ReaderFavorite();
     $rf1->setReaderId($r1->getId());
     $rf1->setBookId($b1->getId());
     $rf1->save();
     $c = new Criteria(ReaderFavoritePeer::DATABASE_NAME);
     $c->add(ReaderFavoritePeer::BOOK_ID, $b1->getId());
     $c->add(ReaderFavoritePeer::READER_ID, $r1->getId());
     $results = ReaderFavoritePeer::doSelectJoinBookOpinion($c);
     $this->assertEquals(1, count($results), "Expected 1 result");
 }
コード例 #5
0
 public static function populateOpinionFavorite($con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     $book1 = BookPeer::doSelectOne(new Criteria(), $con);
     $reader1 = new BookReader();
     $reader1->save($con);
     $bo = new BookOpinion();
     $bo->setBook($book1);
     $bo->setBookReader($reader1);
     $bo->save($con);
     $rf = new ReaderFavorite();
     $rf->setBookOpinion($bo);
     $rf->save($con);
     $con->commit();
 }