public function testFindOneWithClassAndColumn()
 {
     BookstoreDataPopulator::populate();
     BookTableMap::clearInstancePool();
     AuthorTableMap::clearInstancePool();
     ReviewTableMap::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->filterByTitle('The Tin Drum');
     $c->join('Propel\\Tests\\Bookstore\\Book.Author');
     $c->withColumn('Author.FirstName', 'AuthorName');
     $c->withColumn('Author.LastName', 'AuthorName2');
     $c->with('Author');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $books = $c->find($con);
     foreach ($books as $book) {
         break;
     }
     $this->assertTrue($book instanceof Book, 'withColumn() do not change the resulting model class');
     $this->assertEquals('The Tin Drum', $book->getTitle());
     $this->assertTrue($book->getAuthor() instanceof Author, 'ObjectFormatter correctly hydrates with class');
     $this->assertEquals('Gunter', $book->getAuthor()->getFirstName(), 'ObjectFormatter correctly hydrates with class');
     $this->assertEquals('Gunter', $book->getVirtualColumn('AuthorName'), 'ObjectFormatter adds withColumns as virtual columns');
     $this->assertEquals('Grass', $book->getVirtualColumn('AuthorName2'), 'ObjectFormatter correctly hydrates all virtual columns');
 }
 public function testOffset()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->limit(50);
     $c->offset(10);
     if ($this->isDb('mysql')) {
         $sql = 'SELECT  FROM  LIMIT 10, 50';
     } else {
         $sql = 'SELECT  FROM  LIMIT 50 OFFSET 10';
     }
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'offset() adds an OFFSET clause');
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Propel\Runtime\Exception\LogicException
  */
 public function testFindOneWithOneToManyAndLimit()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->add(BookTableMap::COL_ISBN, '043935806X');
     $c->leftJoin('Book.Review');
     $c->with('Review');
     $c->limit(5);
     $books = $c->find();
 }
Ejemplo n.º 4
0
 /**
  * @param ModelCriteria $search
  *
  * @return ObjectCollection
  */
 protected function searchWithOffset(ModelCriteria $search)
 {
     $limit = intval($this->getArgValue('limit'));
     if ($limit >= 0) {
         $search->limit($limit);
     }
     $search->offset(intval($this->getArgValue('offset')));
     return $search->find();
 }
Ejemplo n.º 5
0
 /**
  * Maps options like limit, offset, order
  *
  * @param ModelCriteria $query
  * @param array $options
  *
  * @throws FileNotFoundException
  */
 public function mapOptions(ModelCriteria $query, $options = array())
 {
     if (isset($options['limit'])) {
         $query->limit($options['limit']);
     }
     if (isset($options['offset'])) {
         $query->offset($options['offset']);
     }
     if (isset($options['order']) && is_array($options['order'])) {
         foreach ($options['order'] as $field => $direction) {
             $fieldName = ucfirst($field);
             $tableMap = $this->tableMap;
             if (false !== ($pos = strpos($field, '.'))) {
                 $relationName = ucfirst(substr($field, 0, $pos));
                 $fieldName = ucfirst(substr($field, $pos + 1));
                 if (!($relation = $this->tableMap->getRelation($relationName))) {
                     throw new FileNotFoundException(sprintf('Relation `%s` in object `%s` not found', $relationName, $this->getObjectKey()));
                 }
                 $tableMap = $relation->getForeignTable();
             }
             if ($tableMap->hasColumnByPhpName(ucfirst($fieldName))) {
                 $column = $this->tableMap->getColumnByPhpName(ucfirst($fieldName));
                 $query->orderBy($column->getName(), $direction);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @expectedException \Propel\Runtime\Exception\LogicException
  */
 public function testFindOneWithOneToManyAndLimit()
 {
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->add(BookTableMap::ISBN, '043935806X');
     $c->leftJoin('Propel\\Tests\\Bookstore\\Book.Review');
     $c->with('Review');
     $c->limit(5);
     $books = $c->find();
 }