summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorDracony <draconyster@gmail.com>2013-01-04 14:43:15 +0200
committerDracony <draconyster@gmail.com>2013-01-04 14:43:15 +0200
commit918dc193c8da64bef3522456934fb40c14a2ceda (patch)
treed2a04dbedce54b7ad50161d0bb8a5f81fd611b1e /modules
parentf011e1d14d442cb9572e777513c8972c76f3cfe5 (diff)
downloadPHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.zip
PHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.tar.gz
PHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.tar.bz2
ORM and DB tweeks
Fixed orm to return all rows on find_all() call after find() You cann now reset limit offset and group_by by passing NULL
Diffstat (limited to 'modules')
-rw-r--r--modules/database/classes/database/query.php17
-rw-r--r--modules/orm/classes/orm.php8
2 files changed, 17 insertions, 8 deletions
diff --git a/modules/database/classes/database/query.php b/modules/database/classes/database/query.php
index 5a151bd..5728514 100644
--- a/modules/database/classes/database/query.php
+++ b/modules/database/classes/database/query.php
@@ -11,13 +11,16 @@
* @method mixed data(array $data = null) Set data for insert or update queries.
* Without arguments returns current data, returns self otherwise.
*
- * @method mixed limit(int $limit = null) Set number of rows to return.
+ * @method mixed limit(int $limit = null) Set number of rows to return. If NULL is passed than no limit is used.
+ * If NULL is passed than no limit is used.
* Without arguments returns current limit, returns self otherwise.
*
* @method mixed offset(string $offset = null) Set the offset for the first row in result.
+ * If NULL is passed than no offset is used.
* Without arguments returns current offset, returns self otherwise.
*
* @method mixed group_by(string $group_by = null) A column to group rows by for aggregator functions.
+ * If NULL is passed than no grouping is done.
* Without arguments returns current group_by argument, returns self otherwise.
*
* @method mixed type(string $type = null) Set query type. Available types: select, update, insert, delete, count.
@@ -121,7 +124,7 @@ abstract class Query_Database {
* @var array
* @access protected
*/
- protected $methods = array('table' => 'string','data' => 'array','limit' => 'integer','offset' => 'integer','group_by' => 'string','type' => 'string');
+ protected $methods = array('table' => 'string','data' => 'array','limit' => array('integer','NULL'),'offset' => array('integer','NULL'),'group_by' => array('string','NULL'),'type' => 'string');
/**
* Generates a query in format that can be executed on current database implementation
@@ -176,7 +179,6 @@ abstract class Query_Database {
* @see $methods
*/
public function __call($method, $args) {
-
if (isset($this->methods[$method])) {
$property = '_'.$method;
@@ -185,9 +187,12 @@ abstract class Query_Database {
return $this->$property;
$val = $args[0];
if (is_int($val))
- $val=(int) $val;
- if (gettype($val) != $this->methods[$method])
- throw new Exception("Method '{$method}' only accepts values of type: '{$this->methods[$method]}', '{$val}' was passed");
+ $val = (int) $val;
+ $allowed_types = $this->methods[$method];
+ if (!is_array($allowed_types))
+ $allowed_types=array($allowed_types);
+ if (!in_array(gettype($val),$allowed_types))
+ throw new Exception("Method '{$method}' only accepts values of type: ".implode(' or ',$allowed_types).", '{$val}' was passed");
$this->$property = $val;
return $this;
}
diff --git a/modules/orm/classes/orm.php b/modules/orm/classes/orm.php
index 3f2dc65..4165df6 100644
--- a/modules/orm/classes/orm.php
+++ b/modules/orm/classes/orm.php
@@ -5,9 +5,11 @@
* it is easy to setup and makes a lot of use of naming convention.
*
* @method mixed limit(int $limit = null) Set number of rows to return.
+ * If NULL is passed than no limit is used.
* Without arguments returns current limit, returns self otherwise.
*
* @method mixed offset(int $offset = null) Set the offset for the first row in result.
+ * If NULL is passed than no limit is used.
* Without arguments returns current offset, returns self otherwise.
*
* @method mixed orderby(string $column, string $dir) Adds a column to ordering parameters
@@ -192,8 +194,10 @@ class ORM {
* @access public
*/
public function find() {
- $res=new ORMResult(get_class($this), $res=$this->query->limit(1)->execute());
- return $res->current();
+ $set_limit=$this->limit();
+ $res = $this->limit(1)->find_all()->current();
+ $this->limit($set_limit);
+ return $res;
}
/**