protected function setUp()
 {
     parent::setUp();
     BookstoreDataPopulator::populate();
     $cr = new Criteria();
     $cr->add(AuthorPeer::LAST_NAME, "Rowling");
     $cr->add(AuthorPeer::FIRST_NAME, "J.K.");
     $rowling = AuthorPeer::doSelectOne($cr);
     $this->authorId = $rowling->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Philosopher's Stone");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Chamber of Secrets");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Prisoner of Azkaban");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Goblet of Fire");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Half-Blood Prince");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Deathly Hallows");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
 }
 /**
  * Test reload(deep=true) method.
  */
 public function testReloadDeep()
 {
     BookstoreDataPopulator::populate();
     // arbitrary book
     $b = BookPeer::doSelectOne(new Criteria());
     // arbitrary, different author
     $c = new Criteria();
     $c->add(AuthorPeer::ID, $b->getAuthorId(), Criteria::NOT_EQUAL);
     $a = AuthorPeer::doSelectOne($c);
     $origAuthor = $b->getAuthor();
     $b->setAuthor($a);
     $this->assertNotEquals($origAuthor, $b->getAuthor(), "Expected just-set object to be different from obj from DB");
     $this->assertTrue($b->isModified());
     $b->reload($deep = true);
     $this->assertEquals($origAuthor, $b->getAuthor(), "Expected object in DB to be restored");
     $this->assertFalse($a->isModified());
 }
 public function testRefFKGetJoin()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     PublisherPeer::clearInstancePool();
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $author = AuthorPeer::doSelectOne(new Criteria(), $con);
     // populate book instance pool
     $books = $author->getBooksJoinPublisher(null, $con);
     $sql = $con->getLastExecutedQuery();
     $publisher = $books[0]->getPublisher($con);
     $this->assertEquals($sql, $con->getLastExecutedQuery(), 'refFK getter uses instance pool if possible');
 }
 public function testAddJoinMultipleWithNotInOperator()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new Criteria();
     $c->addMultipleJoin(array(array(AuthorPeer::ID, BookPeer::AUTHOR_ID), array(BookPeer::ISBN, array(1, 7, 42), Criteria::NOT_IN)), Criteria::LEFT_JOIN);
     AuthorPeer::doSelectOne($c, $con);
     $expectedSQL = 'SELECT author.id, author.first_name, author.last_name, author.email, author.age FROM author LEFT JOIN book ON (author.id=book.author_id AND book.isbn NOT IN (1,7,42)) LIMIT 1';
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery());
 }
Пример #5
0
 public function getAuthor(PropelPDO $con = null)
 {
     if ($this->aAuthor === null && $this->author_id !== null) {
         $c = new Criteria(AuthorPeer::DATABASE_NAME);
         $c->add(AuthorPeer::ID, $this->author_id);
         $this->aAuthor = AuthorPeer::doSelectOne($c, $con);
     }
     return $this->aAuthor;
 }