Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Mofasa Kohana Builds Kemal Delalic
Mofasa

Fixed issue

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

Kemal Delalic
Collaborator

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
Commits on Dec 15, 2011
  1. Add as_assoc() and as_object() to support the result render as array …

    Sumh authored
    …or object
    
    Sumh <42424861@qq.com>
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 2 deletions.
  1. +33 −2 classes/kohana/orm.php
35 classes/kohana/orm.php
View
@@ -850,7 +850,8 @@ protected function _build($type)
switch ($type)
{
case Database::SELECT:
- $this->_db_builder = DB::select();
+ // Render the result as object by default
+ $this->_db_builder = DB::select()->as_object(get_class($this));
break;
case Database::UPDATE:
$this->_db_builder = DB::update(array($this->_table_name, $this->_object_name));
@@ -960,7 +961,7 @@ protected function _load_result($multiple = FALSE)
if ($multiple === TRUE)
{
// Return database iterator casting to this object type
- $result = $this->_db_builder->as_object(get_class($this))->execute($this->_db);
+ $result = $this->_db_builder->execute($this->_db);
$this->reset();
@@ -2152,6 +2153,36 @@ public function param($param, $value)
return $this;
}
+ /**
+ * Returns results as associative arrays
+ *
+ * @return $this
+ */
+ public function as_assoc()
+ {
+ $this->_db_pending[] = array(
+ 'name' => 'as_assoc',
+ 'args' => array(),
+ );
+
+ return $this;
+ }
+
+ /**
+ * Returns results as objects
+ *
+ * @return $this
+ */
+ public function as_object()
+ {
+ $this->_db_pending[] = array(
+ 'name' => 'as_object',
+ 'args' => array(get_class($this)),
+ );
+
+ return $this;
+ }
+
/**
* Checks whether a column value is unique.
* Excludes itself if loaded.
Something went wrong with that request. Please try again.