Allow where table1.colum=table2.colum on ModelMySQL.
This commit is contained in:
		| @@ -26,15 +26,16 @@ class ModelMySQL { | ||||
|   static protected $tableSufix = 's'; | ||||
|   static protected $db; | ||||
|   static protected $querySelect = [ | ||||
|                     'select' => '*', | ||||
|                     'where' => '', | ||||
|                     'leftJoin' => '', | ||||
|                     'select'    => '*', | ||||
|                     'where'     => '', | ||||
|                     'from'      => '', | ||||
|                     'leftJoin'  => '', | ||||
|                     'rightJoin' => '', | ||||
|                     'innerJoin' => '', | ||||
|                     'AndOr' => '', | ||||
|                     'orderBy'=>'', | ||||
|                     'groupBy'=>'', | ||||
|                     'limit' => '', | ||||
|                     'AndOr'     => '', | ||||
|                     'orderBy'   => '', | ||||
|                     'groupBy'   => '', | ||||
|                     'limit'     => '', | ||||
|                    ]; | ||||
|  | ||||
|   /* | ||||
| @@ -104,7 +105,7 @@ class ModelMySQL { | ||||
|   *   Contiene la sentencia SQL. | ||||
|   */ | ||||
|   private static function buildQuery() { | ||||
|     $sql = 'SELECT '.static::$querySelect['select']: | ||||
|     $sql = 'SELECT '.static::$querySelect['select']; | ||||
|      | ||||
|     if (static::$querySelect['from'] != '') { | ||||
|       $sql .= ' FROM '.static::$querySelect['from']; | ||||
| @@ -326,11 +327,14 @@ class ModelMySQL { | ||||
|   * @param string $value | ||||
|   *   El valor el valor a comparar en la columna. | ||||
|   * | ||||
|   * @param $is_colum | ||||
|   *   Se usa cuando $value es una columna de la tabla y no un valor | ||||
|   * | ||||
|   * Sintaxis posibles:  | ||||
|   *  - static::where(columna, operador, valor) | ||||
|   *  - static::where(columna, valor)  // Operador por defecto "=" | ||||
|   */ | ||||
|   public static function where($column, $operator, $value=null) { | ||||
|   public static function where($column, $operator, $value=null, $is_colum = false) { | ||||
|     if (is_null($value)) { | ||||
|       $value = $operator; | ||||
|       $operator = '='; | ||||
| @@ -338,7 +342,10 @@ class ModelMySQL { | ||||
|      | ||||
|     $value = static::db()->real_escape_string($value); | ||||
|      | ||||
|     static::$querySelect['where'] = "$column$operator'$value'"; | ||||
|     if ($is_colum) | ||||
|       static::$querySelect['where'] = "$column$operator$value"; | ||||
|     else | ||||
|       static::$querySelect['where'] = "$column$operator'$value'"; | ||||
|      | ||||
|     return new static(); | ||||
|   } | ||||
| @@ -480,12 +487,15 @@ class ModelMySQL { | ||||
|   * @param string $value | ||||
|   *   El valor el valor a comparar en la columna. | ||||
|   * | ||||
|   * @param $is_colum | ||||
|   *   Se usa cuando $value es una columna de la tabla y no un valor | ||||
|   * | ||||
|   * Sintaxis posibles:  | ||||
|   *  - static::and(columna, operador, valor) | ||||
|   *  - static::and(columna, valor)  // Operador por defecto "=" | ||||
|   *  - static::and(columna, valor)->and(columna, valor)->and(columna, valor) // anidado | ||||
|   */ | ||||
|   public static function and($column, $operator, $value=null) { | ||||
|   public static function and($column, $operator, $value=null, $is_colum = false) { | ||||
|     if (is_null($value)) { | ||||
|       $value = $operator; | ||||
|       $operator = '='; | ||||
| @@ -493,7 +503,10 @@ class ModelMySQL { | ||||
|      | ||||
|     $value = static::db()->real_escape_string($value); | ||||
|      | ||||
|     static::$querySelect['AndOr'] .= " AND $column$operator'$value'"; | ||||
|     if ($is_colum) | ||||
|       static::$querySelect['AndOr'] .= " AND $column$operator$value"; | ||||
|     else | ||||
|       static::$querySelect['AndOr'] .= " AND $column$operator'$value'"; | ||||
|      | ||||
|     return new static(); | ||||
|   } | ||||
| @@ -510,12 +523,15 @@ class ModelMySQL { | ||||
|   * @param string $value | ||||
|   *   El valor el valor a comparar en la columna. | ||||
|   * | ||||
|   * @param $is_colum | ||||
|   *   Se usa cuando $value es una columna de la tabla y no un valor | ||||
|   * | ||||
|   * Sintaxis posibles:  | ||||
|   *  - static::or(columna, operador, valor) | ||||
|   *  - static::or(columna, valor)  // Operador por defecto "=" | ||||
|   *  - static::or(columna, valor)->or(columna, valor)->or(columna, valor) // anidado | ||||
|   */ | ||||
|   public static function or($column, $operator, $value=null) { | ||||
|   public static function or($column, $operator, $value=null, $is_colum = false) { | ||||
|     if (is_null($value)) { | ||||
|       $value = $operator; | ||||
|       $operator = '='; | ||||
| @@ -523,7 +539,10 @@ class ModelMySQL { | ||||
|      | ||||
|     $value = static::db()->real_escape_string($value); | ||||
|      | ||||
|     static::$querySelect['AndOr'] .= " OR $column$operator'$value'"; | ||||
|     if ($is_colum) | ||||
|       static::$querySelect['AndOr'] .= " OR $column$operator$value"; | ||||
|     else | ||||
|       static::$querySelect['AndOr'] .= " OR $column$operator'$value'"; | ||||
|      | ||||
|     return new static(); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user