public function testSetRelationMapComposite()
 {
     $table = ReaderFavoriteTableMap::getTableMap();
     $join = new ModelJoin();
     $join->setTableMap($table);
     $join->setRelationMap($table->getRelation('BookOpinion'));
     $this->assertEquals(array(ReaderFavoriteTableMap::COL_BOOK_ID, ReaderFavoriteTableMap::COL_READER_ID), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns for composite relationships');
     $this->assertEquals(array(BookOpinionTableMap::COL_BOOK_ID, BookOpinionTableMap::COL_READER_ID), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns for composite relationships');
 }
 /**
  * @link       http://propel.phpdb.org/trac/ticket/519
  */
 public function testDoDeleteCompositePK()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     ReaderFavoriteTableMap::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, ReaderFavoriteQuery::create()->count());
     // 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)
     ReaderFavoriteTableMap::doDelete(array(array(1, 1), array(2, 2)));
     $this->assertEquals(4, ReaderFavoriteQuery::create()->count());
     //Note: these composite PK's are pairs of (BookId, ReaderId)
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(2, 1)));
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(1, 2)));
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3, 1)));
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3, 2)));
     $this->assertNull(ReaderFavoriteQuery::create()->findPk(array(1, 1)));
     $this->assertNull(ReaderFavoriteQuery::create()->findPk(array(2, 2)));
     //test deletion of a single composite PK
     ReaderFavoriteTableMap::doDelete(array(3, 1));
     $this->assertEquals(3, ReaderFavoriteQuery::create()->count());
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(2, 1)));
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(1, 2)));
     $this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3, 2)));
     $this->assertNull(ReaderFavoriteQuery::create()->findPk(array(1, 1)));
     $this->assertNull(ReaderFavoriteQuery::create()->findPk(array(2, 2)));
     $this->assertNull(ReaderFavoriteQuery::create()->findPk(array(3, 1)));
     //test deleting the last three
     ReaderFavoriteTableMap::doDelete(array(array(2, 1), array(1, 2), array(3, 2)));
     $this->assertEquals(0, ReaderFavoriteQuery::create()->count());
 }
 /**
  * Testing foreign keys with multiple referrer columns.
  * @link       http://propel.phpdb.org/trac/ticket/606
  */
 public function testMultiColFk()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     ReaderFavoriteTableMap::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(ReaderFavoriteTableMap::DATABASE_NAME);
     $c->add(ReaderFavoriteTableMap::BOOK_ID, $b1->getId());
     $c->add(ReaderFavoriteTableMap::READER_ID, $r1->getId());
     $results = ReaderFavoriteQuery::create(null, $c)->joinWith('BookOpinion')->find();
     $this->assertEquals(1, count($results), "Expected 1 result");
 }