Permalink
Browse files

Preventing datasource creationa and access on models having $useTable…

… = false;
  • Loading branch information...
1 parent bc68915 commit 6aa08b5f52955d15fb7e44ed28efcd8156c958d2 @lorenzo lorenzo committed Jan 21, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/Cake/Model/Model.php
  2. +12 −0 lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -1219,7 +1219,7 @@ public function deconstruct($field, $data) {
* @return array Array of table metadata
*/
public function schema($field = false) {
- if (!is_array($this->_schema) || $field === true) {
+ if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) {
$db = $this->getDataSource();
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if (method_exists($db, 'describe') && $this->useTable !== false) {
@@ -2106,4 +2106,16 @@ public function testModelPrefixFromDatasource() {
ConnectionManager::drop('mock');
}
+/**
+ * Tests that calling schema() on a model that is not supposed to use a table
+ * does not trigger any calls on any datasource
+ *
+ * @return void
+ **/
+ public function testSchemaNoDB() {
+ $model = $this->getMock('Article', array('getDataSource'));
+ $model->useTable = false;
+ $model->expects($this->never())->method('getDataSource');
+ $this->assertEmpty($model->schema());
+ }
}

0 comments on commit 6aa08b5

Please sign in to comment.