예제 #1
0
파일: Join.php 프로젝트: Konro1/pms
 public function compile($db = NULL)
 {
     if ($this->context_model() and $meta = Jam::meta(Jam_Query_Builder::aliased_model($this->context_model()))) {
         $db = Database::instance($meta->db());
     }
     $original_on = $this->_on;
     $original_using = $this->_using;
     $original_table = $this->_table;
     if (!empty($this->_on)) {
         foreach ($this->_on as &$condition) {
             $condition[0] = Jam_Query_Builder::resolve_attribute_name($condition[0], $this->model() ? $this->model() : $this->_table);
             $condition[2] = Jam_Query_Builder::resolve_attribute_name($condition[2], $this->context_model());
         }
     }
     $this->_table = Jam_Query_Builder::resolve_table_alias($this->_table);
     if (!empty($this->_using)) {
         foreach ($this->_using as &$column) {
             $column = Jam_Query_Builder::resolve_attribute_name($column, $this->meta());
         }
     }
     $additional_joins = '';
     foreach ($this->_joins as $join) {
         $additional_joins .= ' ' . $join->compile($db);
     }
     $compiled = parent::compile($db) . $additional_joins;
     $this->_on = $original_on;
     $this->_using = $original_using;
     $this->_table = $original_table;
     return $compiled;
 }
예제 #2
0
파일: Builder.php 프로젝트: Konro1/pms
 /**
  * Generate Jam_Query_Builder_Join based on the given arguments
  * @param  string  $table
  * @param  string  $type                LEFT, NATURAL...
  * @param  string  $context_model       the model of the parent
  * @param  boolean $resolve_table_model wether to resolve the name of the model to a tablename
  * @return Jam_Query_Builder_Join
  */
 public static function resolve_join($table, $type = NULL, $context_model = NULL, $resolve_table_model = TRUE)
 {
     $context_model_name = Jam_Query_Builder::aliased_model($context_model);
     if ($resolve_table_model and is_string($context_model_name) and $meta = Jam::meta($context_model_name)) {
         $table_name = Jam_Query_Builder::aliased_model($table);
         if (is_string($table_name) and $association = $meta->association($table_name)) {
             return $association->join(is_array($table) ? $table[1] : NULL, $type);
         }
     }
     $join = Jam_Query_Builder_Join::factory($table, $type);
     if ($context_model) {
         $join->context_model($context_model);
     }
     return $join;
 }