Esempio n. 1
0
 /**
  * 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());
 }
 /**
  * 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 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();
 }