Commit 8e7abbe6 authored by mgralikowski's avatar mgralikowski Committed by Alexander Butenko

Add getValue method for models objects. (#837)

* Add getValue method

Add getValue method for models objects.

* Update dbObject.md

Add info about getValue()

* Update dbObject.php

Add has method to models
parent 810ffe98
......@@ -39,7 +39,7 @@ will not be working with an objects created with `table()` method.
### Selects
Retrieving objects from the database is pretty much the same process as a mysqliDb `get()`/`getOne()` methods without a need to specify table name. All mysqlidb functions like `where()`, `orWhere()`, `orderBy()`, `join()`, etc. are supported.
Retrieving objects from the database is pretty much the same process as a mysqliDb `get()`/`getOne()`/`getValue()` methods without a need to specify table name. All mysqlidb functions like `where()`, `orWhere()`, `orderBy()`, `join()`, etc. are supported.
## Retrieving All Records
......
......@@ -374,7 +374,34 @@ class dbObject {
return $item;
}
/**
* A convenient SELECT COLUMN function to get a single column value from model object
*
* @param string $column The desired column
* @param int $limit Limit of rows to select. Use null for unlimited..1 by default
*
* @return mixed Contains the value of a returned column / array of values
* @throws Exception
*/
protected function getValue ($column, $limit = 1) {
$res = $this->db->ArrayBuilder()->getValue ($this->dbTable, $column, $limit);
if (!$res)
return null;
return $res;
}
/**
* A convenient function that returns TRUE if exists at least an element that
* satisfy the where condition specified calling the "where" method before this one.
*
* @return bool
* @throws Exception
*/
protected function has() {
return $this->db->has($this->dbTable);
}
/**
* Fetch all objects
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment