Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add as_assoc() and as_object() to support the result render as array or ... #49

Closed
wants to merge 1 commit into from

3 participants

Sam Sanchez Kohana Builds Kemal Delalic
Sam Sanchez

Fixed issue

now you can Orm::factory('table')->as_assoc()->find_all()->as_array() to get the result as array

Kemal Delalic
Collaborator
kemo commented

This is an API change, can you please target it agains 3.4/develop? I am closing this PR

Kemal Delalic kemo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 15, 2011
Sumh Add as_assoc() and as_object() to support the result render as array …
…or object

Sumh <42424861@qq.com>
c21716a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 33 additions and 2 deletions. Show diff stats Hide diff stats

  1. +33 2 classes/kohana/orm.php
35 classes/kohana/orm.php
@@ -850,7 +850,8 @@ protected function _build($type)
850 850 switch ($type)
851 851 {
852 852 case Database::SELECT:
853   - $this->_db_builder = DB::select();
  853 + // Render the result as object by default
  854 + $this->_db_builder = DB::select()->as_object(get_class($this));
854 855 break;
855 856 case Database::UPDATE:
856 857 $this->_db_builder = DB::update(array($this->_table_name, $this->_object_name));
@@ -960,7 +961,7 @@ protected function _load_result($multiple = FALSE)
960 961 if ($multiple === TRUE)
961 962 {
962 963 // Return database iterator casting to this object type
963   - $result = $this->_db_builder->as_object(get_class($this))->execute($this->_db);
  964 + $result = $this->_db_builder->execute($this->_db);
964 965
965 966 $this->reset();
966 967
@@ -2152,6 +2153,36 @@ public function param($param, $value)
2152 2153 return $this;
2153 2154 }
2154 2155
  2156 + /**
  2157 + * Returns results as associative arrays
  2158 + *
  2159 + * @return $this
  2160 + */
  2161 + public function as_assoc()
  2162 + {
  2163 + $this->_db_pending[] = array(
  2164 + 'name' => 'as_assoc',
  2165 + 'args' => array(),
  2166 + );
  2167 +
  2168 + return $this;
  2169 + }
  2170 +
  2171 + /**
  2172 + * Returns results as objects
  2173 + *
  2174 + * @return $this
  2175 + */
  2176 + public function as_object()
  2177 + {
  2178 + $this->_db_pending[] = array(
  2179 + 'name' => 'as_object',
  2180 + 'args' => array(get_class($this)),
  2181 + );
  2182 +
  2183 + return $this;
  2184 + }
  2185 +
2155 2186 /**
2156 2187 * Checks whether a column value is unique.
2157 2188 * Excludes itself if loaded.

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.