示例#1
0
 protected function _compile_conditions(Database $db, array $conditions)
 {
     foreach ($conditions as &$group) {
         foreach ($group as &$condition) {
             $condition[0] = Jam_Query_Builder::resolve_attribute_name($condition[0], $this->meta()->model(), $condition[2]);
         }
     }
     return parent::_compile_conditions($db, $conditions);
 }
示例#2
0
文件: sprig.php 项目: Webthink/sprig
 /**
  * Delete the current record:
  *
  * - If the record is loaded, it will be deleted using primary key(s).
  * - If the record is not loaded, it will be deleted using all changed fields.
  * - If no data has been changed, the delete will be ignored.
  *
  * @param   object   any Database_Query_Builder_Delete, NULL for none
  * @return  $this
  */
 public function delete(Database_Query_Builder_Delete $query = NULL)
 {
     if ($query) {
         $query->table($this->_table);
     }
     if ($this->loaded()) {
         if (!$query) {
             $query = DB::delete($this->_table);
         }
         if (is_array($this->_primary_key)) {
             foreach ($this->_primary_key as $field) {
                 $query->where($this->_fields[$field]->column, '=', $this->_original[$field]);
             }
         } else {
             $query->where($this->_fields[$this->_primary_key]->column, '=', $this->_original[$this->_primary_key]);
         }
     } elseif ($changed = $this->changed()) {
         if (!$query) {
             $query = DB::delete($this->_table);
         }
         foreach ($changed as $field => $value) {
             $query->where($this->_fields[$field]->column, '=', $value);
         }
     }
     if (isset($query) and $query->execute($this->_db)) {
         // Reset all object data
         $this->_changed = $this->_original = array();
         foreach ($this->_fields as $name => $field) {
             if ($field->in_db) {
                 // Repopulate the default values for the model
                 $this->_original[$name] = $field->value($field->default);
             }
         }
     }
     return $this;
 }