public function testWithColumnAndSelectColumns()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $sql = $this->getSql('SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, UPPER(book.title) AS foo FROM book');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() adds the object columns if the criteria has no select columns');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.id');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $sql = $this->getSql('SELECT book.id, UPPER(book.title) AS foo FROM book');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() does not add the object columns if the criteria already has select columns');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.id');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $c->addSelectColumn('book.title');
     $sql = $this->getSql('SELECT book.id, book.title, UPPER(book.title) AS foo FROM book');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() does adds as column after the select columns even though the withColumn() method was called first');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.id');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.isbn)', 'isbn');
     $sql = $this->getSql('SELECT book.id, UPPER(book.title) AS foo, UPPER(book.isbn) AS isbn FROM book');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() called repeatedly adds several as columns');
 }
 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');
 }
 /**
  * @api
  *
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $expandableQuery
  * @param string $tableAlias
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function selectCategoryAttributeColumns(ModelCriteria $expandableQuery, $tableAlias = SpyCategoryAttributeTableMap::TABLE_NAME)
 {
     $expandableQuery->withColumn($tableAlias . '.name', 'category_name');
     $expandableQuery->withColumn($tableAlias . '.meta_title', 'category_meta_title');
     $expandableQuery->withColumn($tableAlias . '.meta_description', 'category_meta_description');
     $expandableQuery->withColumn($tableAlias . '.meta_keywords', 'category_meta_keywords');
     $expandableQuery->withColumn($tableAlias . '.category_image_name', 'category_image_name');
     return $expandableQuery;
 }
示例#4
0
 /**
  * @api
  *
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $expandableQuery
  *
  * @return $this
  */
 public function joinTaxRates(ModelCriteria $expandableQuery)
 {
     $expandableQuery->addJoin(SpyTaxSetTableMap::COL_ID_TAX_SET, SpyTaxSetTaxTableMap::COL_FK_TAX_SET, Criteria::LEFT_JOIN)->addJoin(SpyTaxSetTaxTableMap::COL_FK_TAX_RATE, SpyTaxRateTableMap::COL_ID_TAX_RATE, Criteria::LEFT_JOIN);
     $expandableQuery->withColumn('GROUP_CONCAT(DISTINCT ' . SpyTaxRateTableMap::COL_NAME . ')', 'tax_rate_names')->withColumn('GROUP_CONCAT(DISTINCT ' . SpyTaxRateTableMap::COL_RATE . ')', 'tax_rate_rates');
     return $this;
 }
示例#5
0
文件: Propel.php 项目: jarves/jarves
 /**
  * @param ModelCriteria $query
  * @param RelationMap[] $relations
  * @param string[][] $relationFields
  */
 public function mapToOneRelationFields(&$query, $relations, $relationFields)
 {
     if ($relations) {
         foreach ($relations as $name => $relation) {
             if ($relation->getType() != RelationMap::MANY_TO_MANY && $relation->getType() != RelationMap::ONE_TO_MANY) {
                 $query->{'join' . $name}($name);
                 //$query->with($name);
                 if (isset($relationFields[$name])) {
                     foreach ($relationFields[$name] as $col) {
                         $query->withColumn($name . "." . $col, '"' . $name . "." . $col . '"');
                     }
                 }
             }
         }
     }
 }
 public function testSelectArrayWithColumn()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->join('Propel\\Tests\\Bookstore\\Book.Author');
     $c->withColumn('LOWER(Propel\\Tests\\Bookstore\\Book.Title)', 'LowercaseTitle');
     $c->select(array('LowercaseTitle', 'Propel\\Tests\\Bookstore\\Book.Title'));
     $c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
     $rows = $c->find($this->con);
     $expectedSQL = $this->getSql('SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Propel\\Tests\\Bookstore\\Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC');
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
     $expectedRows = array(array('LowercaseTitle' => 'don juan', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Propel\\Tests\\Bookstore\\Book.Title' => 'The Tin Drum'));
     $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
 }
示例#7
0
 public function testFindOneWithClassAndColumn()
 {
     BookstoreDataPopulator::populate();
     BookTableMap::clearInstancePool();
     AuthorTableMap::clearInstancePool();
     ReviewTableMap::clearInstancePool();
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $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');
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $book = $c->findOne($con);
     $this->assertEquals(array('Id', 'Title', 'ISBN', 'Price', 'PublisherId', 'AuthorId', 'Author', 'AuthorName', 'AuthorName2'), array_keys($book), 'withColumn() do not change the resulting model class');
     $this->assertEquals('The Tin Drum', $book['Title']);
     $this->assertEquals('Gunter', $book['Author']['FirstName'], 'ArrayFormatter correctly hydrates withclass and columns');
     $this->assertEquals('Gunter', $book['AuthorName'], 'ArrayFormatter adds withColumns as columns');
     $this->assertEquals('Grass', $book['AuthorName2'], 'ArrayFormatter correctly hydrates all as columns');
 }
 public function testWithColumnAndSelectColumns()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $sql = $this->getSql('SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, UPPER(book.TITLE) AS foo FROM `book`');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() adds the object columns if the criteria has no select columns');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.ID');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $sql = $this->getSql('SELECT book.ID, UPPER(book.TITLE) AS foo FROM `book`');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() does not add the object columns if the criteria already has select columns');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.ID');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $c->addSelectColumn('book.TITLE');
     $sql = $this->getSql('SELECT book.ID, book.TITLE, UPPER(book.TITLE) AS foo FROM `book`');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() does adds as column after the select columns even though the withColumn() method was called first');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->addSelectColumn('book.ID');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.Title)', 'foo');
     $c->withColumn('UPPER(Propel\\Tests\\Bookstore\\Book.ISBN)', 'isbn');
     $sql = $this->getSql('SELECT book.ID, UPPER(book.TITLE) AS foo, UPPER(book.ISBN) AS isbn FROM `book`');
     $params = array();
     $this->assertCriteriaTranslation($c, $sql, $params, 'withColumn() called repeatedly adds several as columns');
 }
示例#9
0
 public static function getBackEndI18n(ModelCriteria &$search, $requestedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
 {
     if ($foreignTable === null) {
         $foreignTable = $search->getTableMap()->getName();
         $aliasPrefix = '';
     } else {
         $aliasPrefix = $foreignTable . '_';
     }
     $requestedLocaleI18nAlias = $aliasPrefix . 'requested_locale_i18n';
     $requestedLocaleJoin = new Join();
     $requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
     $requestedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
     $search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)->addJoinCondition($requestedLocaleI18nAlias, '`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
     $search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
     foreach ($columns as $column) {
         $search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
     }
 }
示例#10
0
 /**
  * @api
  *
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $expandableQuery
  * @param \Generated\Shared\Transfer\LocaleTransfer $locale
  *
  * @return $this
  */
 public function joinProductQueryWithLocalizedAttributes(ModelCriteria $expandableQuery, LocaleTransfer $locale)
 {
     $expandableQuery->addJoin(SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT, SpyProductAbstractLocalizedAttributesTableMap::COL_FK_PRODUCT_ABSTRACT, Criteria::INNER_JOIN);
     $expandableQuery->addJoin(SpyProductAbstractLocalizedAttributesTableMap::COL_FK_LOCALE, SpyLocaleTableMap::COL_ID_LOCALE, Criteria::INNER_JOIN);
     $expandableQuery->addAnd(SpyLocaleTableMap::COL_ID_LOCALE, $locale->getIdLocale(), Criteria::EQUAL);
     $expandableQuery->addAnd(SpyLocaleTableMap::COL_IS_ACTIVE, true, Criteria::EQUAL);
     $expandableQuery->addJoinObject((new Join(SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT, SpyUrlTableMap::COL_FK_RESOURCE_PRODUCT_ABSTRACT, Criteria::LEFT_JOIN))->setRightTableAlias('product_urls'), 'productUrlsJoin');
     $expandableQuery->addJoinCondition('productUrlsJoin', 'product_urls.fk_locale = ' . SpyLocaleTableMap::COL_ID_LOCALE);
     $expandableQuery->addJoinObject(new Join(SpyProductTableMap::COL_ID_PRODUCT, SpyProductLocalizedAttributesTableMap::COL_FK_PRODUCT, Criteria::INNER_JOIN), 'productAttributesJoin');
     $expandableQuery->addJoinCondition('productAttributesJoin', SpyProductLocalizedAttributesTableMap::COL_FK_LOCALE . ' = ' . SpyLocaleTableMap::COL_ID_LOCALE);
     $expandableQuery->withColumn(SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT, 'id_product_abstract');
     $expandableQuery->withColumn(SpyProductAbstractTableMap::COL_ATTRIBUTES, 'abstract_attributes');
     $expandableQuery->withColumn(SpyProductAbstractLocalizedAttributesTableMap::COL_ATTRIBUTES, 'abstract_localized_attributes');
     $expandableQuery->withColumn("GROUP_CONCAT(spy_product.attributes SEPARATOR '\$%')", 'concrete_attributes');
     $expandableQuery->withColumn("GROUP_CONCAT(spy_product_localized_attributes.attributes SEPARATOR '\$%')", 'concrete_localized_attributes');
     $expandableQuery->withColumn('GROUP_CONCAT(product_urls.url)', 'product_urls');
     $expandableQuery->withColumn(SpyProductAbstractLocalizedAttributesTableMap::COL_NAME, 'abstract_name');
     $expandableQuery->withColumn('GROUP_CONCAT(spy_product_localized_attributes.name)', 'concrete_names');
     return $this;
 }
示例#11
0
文件: Api.php 项目: c15k0/psfs
 /**
  * Add extra columns to pagination query
  *
  * @param ModelCriteria $query
  */
 private function addExtraColumns(ModelCriteria &$query)
 {
     if (!empty($this->extraColumns)) {
         foreach ($this->extraColumns as $expression => $columnName) {
             $query->withColumn($expression, $columnName);
         }
     }
 }