示例#1
0
 public function getCondition()
 {
     if (is_callable($this->condition)) {
         return call_user_func($this->condition);
     }
     return WhereClause::create($this->condition);
 }
示例#2
0
 /**
  * @test
  */
 public function shouldBuildNotExistsClause()
 {
     // when
     $result = WhereClause::notExists(Product::where(array('name' => 'phone')));
     // then
     $this->assertEquals(array('phone'), $result->getParameters());
     Assert::thatString($result->toSql())->startsWith('NOT EXISTS (SELECT')->endsWith('FROM products WHERE name = ?)');
 }
示例#3
0
 private function whereWithUsing()
 {
     $usingClauses = $this->_query->usingClauses;
     $whereClauses = Arrays::map($usingClauses, function (JoinClause $usingClause) {
         return WhereClause::create($usingClause->getJoinColumnWithTable() . ' = ' . $usingClause->getJoinedColumnWithTable());
     });
     return $this->_where(array_merge($whereClauses, $this->_query->whereClauses));
 }
示例#4
0
 public function asJoinClause()
 {
     $joinedModel = $this->relation->getRelationModelObject();
     $joinTable = $joinedModel->getTableName();
     $joinKey = $this->relation->getForeignKey();
     $idName = $this->relation->getLocalKey();
     $onClauses = array(WhereClause::create($this->on), $this->relation->getCondition());
     return new JoinClause($joinTable, $joinKey, $idName, $this->fromTable, $this->alias, $this->type, $onClauses);
 }
示例#5
0
 /**
  * @test
  */
 public function shouldNotReplaceWhenTableNameIsPartOfOtherTableName()
 {
     //given
     $onClauses = array(WhereClause::create('products.active = true'), WhereClause::create('order_products.active = true'));
     $joinClause = new JoinClause('products', 'id', 'product_id', 'order_products', 'p', 'LEFT', $onClauses);
     //when
     $buildJoinQueryPart = DialectUtil::buildJoinQueryPart($joinClause);
     //then
     Assert::thatString($buildJoinQueryPart)->isEqualTo('LEFT JOIN products AS p ON p.id = order_products.product_id AND p.active = true AND order_products.active = true');
 }
示例#6
0
 public function __construct($attributes = array())
 {
     parent::__construct(array('hasMany' => array('products' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category'), 'products_starting_with_b' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category', 'conditions' => "products.name LIKE 'b%'"), 'products_ending_with_b_or_y' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category', 'conditions' => function () {
         return WhereClause::create("products.name LIKE ? OR products.name LIKE ?", array('%b', '%y'));
     }), 'products_name_bob' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category', 'conditions' => array("products.name" => "bob")), 'products_ordered_by_name' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category', 'order' => array("products.name ASC"))), 'hasOne' => array('product_named_billy' => array('class' => 'Test\\Product', 'foreignKey' => 'id_category', 'conditions' => "products.name = 'billy'")), 'belongsTo' => array('parent' => array('class' => 'Test\\Category', 'foreignKey' => 'id_parent', 'referencedColumn' => 'id')), 'attributes' => $attributes, 'fields' => $this->_fields));
 }
示例#7
0
文件: Query.php 项目: letsdrink/ouzo
 public function join($joinTable, $joinKey, $idName, $alias = null, $type = 'LEFT', $on = array())
 {
     $onClauses = array(WhereClause::create($on));
     $this->joinClauses[] = new JoinClause($joinTable, $joinKey, $idName, $this->aliasTable ?: $this->table, $alias, $type, $onClauses);
     return $this;
 }
示例#8
0
 /**
  * @test
  */
 public function shouldFindWhereExists()
 {
     //given
     Product::create(array('name' => 'other'));
     $product = Product::create(array('name' => 'phones'));
     $order = Order::create(array('name' => 'a'));
     OrderProduct::create(array('id_order' => $order->getId(), 'id_product' => $product->getId()));
     //when
     $products = Product::where(WhereClause::exists(OrderProduct::where('id_product = products.id')))->fetchAll();
     //then
     $this->assertCount(1, $products);
     $this->assertEquals($product->getId(), $products[0]->getId());
 }
示例#9
0
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function shouldFailForNotSupportedParameter()
 {
     WhereClause::create(1);
 }
示例#10
0
 public static function buildWhereQueryPart(WhereClause $whereClause)
 {
     return $whereClause->toSql();
 }