/**
  * Returns a new BookQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   BookQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return BookQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof BookQuery) {
         return $criteria;
     }
     $query = new BookQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function testFrom()
 {
     $q = PropelQuery::from('Book');
     $expected = new BookQuery();
     $this->assertEquals($expected, $q, 'from() returns a Model query instance based on the model name');
     $q = PropelQuery::from('Book b');
     $expected = new BookQuery();
     $expected->setModelAlias('b');
     $this->assertEquals($expected, $q, 'from() sets the model alias if found after the blank');
     $q = PropelQuery::from('myBook');
     $expected = new myBookQuery();
     $this->assertEquals($expected, $q, 'from() can find custom query classes');
     try {
         $q = PropelQuery::from('Foo');
         $this->fail('PropelQuery::from() throws an exception when called on a non-existing query class');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'PropelQuery::from() throws an exception when called on a non-existing query class');
     }
 }
 public function testQuery()
 {
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
     $q = new BookQuery();
     $book = $q->setModelAlias('b')->where('b.Title like ?', 'Don%')->orderBy('b.ISBN', 'desc')->findOne();
     $this->assertTrue($book instanceof Book);
     $this->assertEquals('Don Juan', $book->getTitle());
 }