Skip to content

Commit

Permalink
Add getValue method for models objects. (#837)
Browse files Browse the repository at this point in the history
* Add getValue method

Add getValue method for models objects.

* Update dbObject.md

Add info about getValue()

* Update dbObject.php

Add has method to models
  • Loading branch information
mgralikowski authored and avbdr committed Jun 8, 2019
1 parent 810ffe9 commit 8e7abbe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbObject.md
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions dbObject.php
Expand Up @@ -374,7 +374,34 @@ protected function getOne ($fields = null) {

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
*
Expand Down

0 comments on commit 8e7abbe

Please sign in to comment.