create() public static method

public static create ( $where, $parameters = [] )
Beispiel #1
0
 public function getCondition()
 {
     if (is_callable($this->condition)) {
         return call_user_func($this->condition);
     }
     return WhereClause::create($this->condition);
 }
Beispiel #2
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));
 }
Beispiel #3
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);
 }
Beispiel #4
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');
 }
Beispiel #5
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));
 }
Beispiel #6
0
 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;
 }
Beispiel #7
0
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function shouldFailForNotSupportedParameter()
 {
     WhereClause::create(1);
 }