DbObject: add loadAll method

This commit is contained in:
Thomas Gelf 2015-06-11 22:48:07 +02:00
parent 6475e0495a
commit e4e31268c2
1 changed files with 20 additions and 0 deletions

View File

@ -738,6 +738,26 @@ abstract class DbObject
return $obj; return $obj;
} }
public static function loadAll(DbConnection $connection)
{
$objects = array();
$class = get_called_class();
$db = $connection->getConnection();
$dummy = new $class();
$select = $db->select()->from($dummy->table);
$rows = $db->fetchAll($select);
foreach ($rows as $row) {
$obj = new $class();
$obj->connection = $connection;
$obj->setDb($db)->setDbProperties($row);
$objects[] = $obj;
}
return $objects;
}
public static function exists($id, DbConnection $connection) public static function exists($id, DbConnection $connection)
{ {
$class = get_called_class(); $class = get_called_class();