コード例 #1
0
ファイル: ModelQueryBuilder.php プロジェクト: letsdrink/ouzo
 private function addJoin(ModelJoin $modelJoin)
 {
     if (!$this->isAlreadyJoined($modelJoin)) {
         $this->_query->addJoin($modelJoin->asJoinClause());
         $this->_joinedModels[] = $modelJoin;
         if ($modelJoin->storeField()) {
             $this->selectModelColumns($modelJoin->getModelObject(), $modelJoin->alias());
         }
     }
 }
コード例 #2
0
ファイル: QueryExecutorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldHandleSubQueries()
 {
     //given
     Product::create(array('name' => 'prod1', 'description' => 'd'));
     Product::create(array('name' => 'prod1', 'description' => 'd'));
     Product::create(array('name' => 'prod2', 'description' => 'd'));
     $query = Query::select(array('count(*) AS c'))->from(Query::select(array('name', 'count(*) c'))->from('products')->groupBy('name')->where(array('description' => 'd')), 'sub')->where(array('c' => 2));
     $executor = QueryExecutor::prepare(Db::getInstance(), $query);
     //when
     $result = $executor->fetch();
     //then
     $this->assertEquals(array('c' => 1), $result);
 }
コード例 #3
0
ファイル: Query.php プロジェクト: letsdrink/ouzo
 public static function update($attributes)
 {
     return Query::newInstance(QueryType::$UPDATE)->attributes($attributes);
 }
コード例 #4
0
ファイル: Model.php プロジェクト: letsdrink/ouzo
 public function update()
 {
     $this->_callBeforeSaveCallbacks();
     $attributes = $this->getAttributesForUpdate();
     if ($attributes) {
         $query = Query::update($attributes)->table($this->_modelDefinition->table)->where(array($this->_modelDefinition->primaryKey => $this->getId()));
         QueryExecutor::prepare($this->_modelDefinition->db, $query)->execute();
     }
     $this->_callAfterSaveCallbacks();
 }
コード例 #5
0
ファイル: QueryTest.php プロジェクト: letsdrink/ouzo
 /**
  * @group non-sqlite3
  * @test
  */
 public function selectShouldNotLockForUpdateByDefault()
 {
     // when
     $query = Query::select();
     // then
     $this->assertFalse($query->lockForUpdate);
 }
コード例 #6
0
ファイル: MySqlDialectTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldReturnSelectWithMultipleJoinsWithAliases()
 {
     //given
     $query = new Query();
     $query->table = 'products';
     $query->join('categories', 'id_category', 'id_category', 'c')->join('orders', 'id', 'id_product', 'o')->where('id = ?', 1);
     //when
     $sql = $this->_dialect->buildQuery($query);
     //then
     $expected = 'SELECT * FROM products LEFT JOIN categories AS c ON c.id_category = products.id_category LEFT JOIN orders AS o ON o.id = products.id_product WHERE id = ?';
     $this->assertEquals($expected, $sql);
 }
コード例 #7
0
 /**
  * @test
  */
 public function shouldBuildUpdateQuery()
 {
     //given
     $query = new Query();
     $query->table = 'products';
     $query->type = QueryType::$UPDATE;
     $query->updateAttributes = array('col1' => 'val1', 'col2' => 'val2');
     $query->where(array('col1' => 'prev1', 'col2' => 'prev2'));
     //when
     $sql = $this->dialect->buildQuery($query);
     //then
     $this->assertEquals("UPDATE products SET col1 = ?, col2 = ? WHERE col1 = ? AND col2 = ?", $sql);
 }