DbObject: add loadWithAutoIncId
This commit is contained in:
parent
11892d3e78
commit
82a893b06c
|
@ -734,6 +734,13 @@ abstract class DbObject
|
||||||
|
|
||||||
protected function createWhere()
|
protected function createWhere()
|
||||||
{
|
{
|
||||||
|
if ($id = $this->getAutoincId()) {
|
||||||
|
return $this->db->quoteInto(
|
||||||
|
sprintf('%s = ?', $this->autoincKeyName),
|
||||||
|
$id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$key = $this->getKeyName();
|
$key = $this->getKeyName();
|
||||||
if (is_array($key) && ! empty($key)) {
|
if (is_array($key) && ! empty($key)) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
@ -827,6 +834,18 @@ abstract class DbObject
|
||||||
return $obj;
|
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)
|
public static function load($id, DbConnection $connection)
|
||||||
{
|
{
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
|
|
Loading…
Reference in New Issue