DbObject: add loadWithAutoIncId

This commit is contained in:
Thomas Gelf 2015-10-26 12:05:37 +01:00
parent 11892d3e78
commit 82a893b06c
1 changed files with 19 additions and 0 deletions

View File

@ -734,6 +734,13 @@ abstract class DbObject
protected function createWhere()
{
if ($id = $this->getAutoincId()) {
return $this->db->quoteInto(
sprintf('%s = ?', $this->autoincKeyName),
$id
);
}
$key = $this->getKeyName();
if (is_array($key) && ! empty($key)) {
$where = array();
@ -827,6 +834,18 @@ abstract class DbObject
return $obj;
}
public static function loadWithAutoIncId($id, DbConnection $connection)
{
// TODO: Index for prefetch?
$class = get_called_class();
$obj = new $class();
$obj->setConnection($connection)
->set($obj->autoincKeyName, $id)
->loadFromDb();
return $obj;
}
public static function load($id, DbConnection $connection)
{
$class = get_called_class();