Skip to content

Commit 8e7abbe

Browse files
mgralikowskiavbdr
authored andcommitted
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
1 parent 810ffe9 commit 8e7abbe

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

dbObject.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ will not be working with an objects created with `table()` method.
3939

4040

4141
### Selects
42-
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.
42+
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.
4343

4444
## Retrieving All Records
4545

dbObject.php

+27
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,34 @@ protected function getOne ($fields = null) {
374374

375375
return $item;
376376
}
377+
378+
/**
379+
* A convenient SELECT COLUMN function to get a single column value from model object
380+
*
381+
* @param string $column The desired column
382+
* @param int $limit Limit of rows to select. Use null for unlimited..1 by default
383+
*
384+
* @return mixed Contains the value of a returned column / array of values
385+
* @throws Exception
386+
*/
387+
protected function getValue ($column, $limit = 1) {
388+
$res = $this->db->ArrayBuilder()->getValue ($this->dbTable, $column, $limit);
389+
if (!$res)
390+
return null;
391+
return $res;
392+
}
377393

394+
/**
395+
* A convenient function that returns TRUE if exists at least an element that
396+
* satisfy the where condition specified calling the "where" method before this one.
397+
*
398+
* @return bool
399+
* @throws Exception
400+
*/
401+
protected function has() {
402+
return $this->db->has($this->dbTable);
403+
}
404+
378405
/**
379406
* Fetch all objects
380407
*

0 commit comments

Comments
 (0)