diff --git a/library/Director/Data/Db/DbObject.php b/library/Director/Data/Db/DbObject.php index 93ac13c4..cce2bb47 100644 --- a/library/Director/Data/Db/DbObject.php +++ b/library/Director/Data/Db/DbObject.php @@ -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();