addCondition() 공개 메소드

It tries to be smart about where and how the field is defined. $field can be passed as: - string (field name in this model) - Field object - DSQL expression - array (see note below) $cond can be passed as: - string ('=', '>', '<=', etc.) - value can be passed here, then it's used as $value with condition '=' $value can be passed as: - string, integer, boolean or any other simple data type - Field object - DSQL expreession NOTE: $field can be passed as array of conditions. Then all conditions will be joined with OR using DSQLs orExpr method. For example, $model->addCondition(array( array('profit', '=', null), array('profit', '<', 1000), )); will generate "WHERE profit is null OR profit < 1000" EXAMPLES: you can pass [dsql, dsql, dsql ...] and this will be treated as (dsql OR dsql OR dsql) ... you can pass [[field,cond,value], [field,cond,value], ...] and this will be treated as (field=value OR field=value OR ...) BTW, you can mix these too :) [[field,cond,value], dsql, [field,cond,value], ...] will become (field=value OR dsql OR field=value) Value also can be DSQL expression, so following will work nicely: [dsql,'>',dsql] will become (dsql > dsql) [dsql, dsql] will become (dsql = dsql) [field, cond, dsql] will become (field = dsql)
public addCondition ( mixed $field, mixed $cond = UNDEFINED, mixed $value = UNDEFINED, DB_dsql $dsql = null )
$field mixed Field for comparing or array of conditions
$cond mixed Condition
$value mixed Value for comparing
$dsql DB_dsql DSQL object to which conditions will be added
예제 #1
0
파일: Many.php 프로젝트: atk4/atk4
 public function ref($mode = null)
 {
     if (!$this->owner->loaded()) {
         throw $this->exception('Model must be loaded before traversing reference');
     }
     if ($mode == 'model') {
         /** @type SQL_Model $m */
         $m = $this->add($this->model_name);
         return $m->addCondition($this->their_field, $this->owner->get($this->our_field));
     }
     $this->restoreConditions();
     $this->model->unload();
     return $this->model->addCondition($this->their_field, $this->owner->get($this->our_field));
 }