Skip to content

Commit

Permalink
model和orm的数据库连接对象使用自身独立构造出的对象,避免和Database::instance()中的对象在使用QueryBuil…
Browse files Browse the repository at this point in the history
…der时产生冲突
  • Loading branch information
breath-co2 committed Mar 13, 2013
1 parent 3ce885f commit cc4a151
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion core/classes/model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class Core_Model
*/
protected $cache_last_key = null;

/**
* 当前数据库对象
*
* @var Database
*/
protected $_database_instance = null;

/**
* 清除缓慢模式
*
Expand All @@ -69,7 +76,12 @@ public function __construct()
*/
protected function db()
{
return Database::instance($this->database);
if (null===$this->_database_instance)
{
$this->_database_instance = new Database($this->database);
}

return $this->_database_instance;
}

/**
Expand Down
14 changes: 13 additions & 1 deletion core/classes/oop/orm/finder/db.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class Core_OOP_ORM_Finder_DB extends OOP_ORM
*/
protected $tablename;

/**
* 当前数据库对象
*
* @var Database
*/
protected $_database_instance = null;

function __construct()
{
if ( null === $this->tablename )
Expand Down Expand Up @@ -171,7 +178,12 @@ protected function _get_id_field_cache_data( &$bulider , &$id_cache_data )
*/
public function driver()
{
return Database::instance($this->database);
if (null===$this->_database_instance)
{
$this->_database_instance = new Database($this->database);
}

return $this->_database_instance;
}

/**
Expand Down

0 comments on commit cc4a151

Please sign in to comment.