Skip to content

Commit dad5c0e

Browse files
committed
added count calculation
1 parent 0c920d6 commit dad5c0e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ foreach ($project->todos as $project_todo)
101101
}
102102
```
103103

104+
Calculations
105+
------------
106+
107+
See how many records are in your model's table.
108+
109+
```php
110+
$this->todo_model->count();
111+
```
112+
104113
Callbacks/Observers
105114
-------------------
106115

core/MY_Model.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ public function order($criteria, $order_by = 'ASC')
274274
return $this;
275275
}
276276

277+
/**
278+
* Limit the number of records to return.
279+
*
280+
* @param int $limit
281+
* @return MY_Model
282+
*/
277283
public function limit($limit)
278284
{
279285
$this->limit_value = $limit;
@@ -284,6 +290,12 @@ public function limit($limit)
284290
return $this;
285291
}
286292

293+
/**
294+
* Skip a number of records.
295+
*
296+
* @param int $offset
297+
* @return MY_Model
298+
*/
287299
public function offset($offset)
288300
{
289301
$this->offset_value = $offset;
@@ -309,6 +321,16 @@ public function includes($relationship)
309321
}
310322
return $this;
311323
}
324+
325+
/**
326+
* Count the records in a table.
327+
*
328+
* @return int
329+
*/
330+
public function count()
331+
{
332+
return $this->connection->count_all_results($this->table_name);
333+
}
312334

313335
/**
314336
* Trigger a callback and call its observers.

0 commit comments

Comments
 (0)