Пример #1
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()));
 }
Пример #2
0
 /**
  * @link       http://propel.phpdb.org/trac/ticket/519
  */
 public function testDoDeleteCompositePK()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     ReaderFavoritePeer::doDeleteAll();
     // Create book and reader with ID 1
     // Create book and reader with ID 2
     $this->createBookWithId(1);
     $this->createBookWithId(2);
     $this->createReaderWithId(1);
     $this->createReaderWithId(2);
     for ($i = 1; $i <= 2; $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(4, ReaderFavoritePeer::doCount(new Criteria()));
     // Now delete 2 of those rows
     ReaderFavoritePeer::doDelete(array(array(1, 1), array(2, 2)));
     $this->assertEquals(2, ReaderFavoritePeer::doCount(new Criteria()));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2, 1));
     $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1, 2));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(1, 1));
     $this->assertNull(ReaderFavoritePeer::retrieveByPK(2, 2));
 }