예제 #1
0
 public function testUseQueryCustomRelationPhpNameAndAlias()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreContest');
     $c->leftJoin('Propel\\Tests\\Bookstore\\BookstoreContest.Work w');
     $c2 = $c->useQuery('w');
     $this->assertTrue($c2 instanceof BookQuery, 'useQuery() returns a secondary Criteria');
     $this->assertEquals($c, $c2->getPrimaryCriteria(), 'useQuery() sets the primary Criteria os the secondary Criteria');
     $this->assertEquals(array('w' => 'book'), $c2->getAliases(), 'useQuery() sets the secondary Criteria alias correctly');
     $c2->where('w.Title = ?', 'War And Peace');
     $c = $c2->endUse();
     $this->assertEquals('Propel\\Tests\\Bookstore\\BookstoreContest', $c->getModelName(), 'endUse() returns the Primary Criteria');
     $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
     $c->find($con);
     $expectedSQL = "SELECT bookstore_contest.BOOKSTORE_ID, bookstore_contest.CONTEST_ID, bookstore_contest.PRIZE_BOOK_ID FROM `bookstore_contest` LEFT JOIN `book` `w` ON (bookstore_contest.PRIZE_BOOK_ID=w.ID) WHERE w.TITLE = 'War And Peace'";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'useQuery() and endUse() allow to merge a secondary criteria');
 }