diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index a318cfced..0b2ea1cd7 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -184,12 +184,18 @@ class DboPostgres extends DboSource { $fields[$c['name']] = array( 'type' => $this->column($c['type']), 'null' => ($c['null'] == 'NO' ? false : true), - 'default' => preg_replace('/::.*/', '', $c['default']), + 'default' => preg_replace("/^'(.*)'$/", "$1", preg_replace('/::.*/', '', $c['default'])), 'length' => $length ); - if (preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) { - $this->_sequenceMap[$table][$c['name']] = $seq[1]; + if ($c['name'] == $model->primaryKey) { + $fields[$c['name']]['key'] = 'primary'; + $fields[$c['name']]['length'] = 11; + } + if ($fields[$c['name']]['default'] == 'NULL' || preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) { $fields[$c['name']]['default'] = null; + if (!empty($seq) && isset($seq[1])) { + $this->_sequenceMap[$table][$c['name']] = $seq[1]; + } } } } @@ -515,6 +521,9 @@ class DboPostgres extends DboSource { if (strpos($col, 'timestamp') !== false) { return 'datetime'; } + if (strpos($col, 'time') === 0) { + return 'time'; + } if ($col == 'inet') { return('inet'); } diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 5e48ad1d3..f02b7ad1e 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1723,15 +1723,15 @@ class Model extends Overloadable { $valuePath = "{n}.{$this->alias}.{$this->displayField}"; $groupPath = null; } else { - if (!is_array($query['fields']) ) { + if (!is_array($query['fields'])) { $query['fields'] = String::tokenize($query['fields']); } - if (count($query['fields']) == 1 ) { + if (count($query['fields']) == 1) { $keyPath = "{n}.{$this->alias}.{$this->primaryKey}"; $valuePath = '{n}.' . $query['fields'][0]; $groupPath = null; $query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]); - } elseif (count($query['fields']) == 3 ) { + } elseif (count($query['fields']) == 3) { $keyPath = '{n}.' . $query['fields'][0]; $valuePath = '{n}.' . $query['fields'][1]; $groupPath = '{n}.' . $query['fields'][2]; diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 6c04f1d91..e8e55d6f0 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -627,14 +627,15 @@ class ModelTest extends CakeTestCase { $ts = date('Y-m-d H:i:s'); $this->model->save(); + $this->model->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC'; $result = $this->model->findById(1); $expected = array( 'Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $ts), 'SomethingElse' => array( - array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')), array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '1')), + array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', + 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')), array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'JoinThing' => array('doomed' => null, 'something_id' => '1', 'something_else_id' => '3')))); $this->assertEqual($result, $expected); @@ -737,7 +738,6 @@ class ModelTest extends CakeTestCase { $result = $this->model->create(); $expected = array('Article' => array('published' => 'N')); $this->assertEqual($result, $expected); - } function testCreationOfEmptyRecord() { @@ -1364,8 +1364,13 @@ class ModelTest extends CakeTestCase { array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))))); $this->assertEqual($result, $expected); } - +/** + * @todo Figure out why Featured is not getting truncated properly + */ function testRecursiveFindAll() { + $db =& ConnectionManager::getDataSource('test_suite'); + $db->truncate(new Featured()); + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'Featured', 'Category'); $this->model =& new Article(); @@ -1429,7 +1434,7 @@ class ModelTest extends CakeTestCase { $this->Featured->bindModel(array( 'belongsTo' => array( 'ArticleFeatured' => array( - 'conditions' => 'ArticleFeatured.published = \'Y\'', + 'conditions' => "ArticleFeatured.published = 'Y'", 'fields' => 'id, title, user_id, published' ) ) @@ -1990,8 +1995,7 @@ class ModelTest extends CakeTestCase { uses('xml'); } $Article = new Article(); - $result = $Article->save(new Xml('
')); - $this->assertTrue($result); + $this->assertTrue($Article->save(new Xml('
'))); $results = $Article->find(array('Article.title' => 'test xml')); $this->assertTrue($results); @@ -2298,10 +2302,10 @@ class ModelTest extends CakeTestCase { array('title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'author_id' => 2) )); - $result = $this->model->find('all', array('recursive' => -1)); + $result = $this->model->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $expected = array( - array('Post' => array('id' => '6', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)), - array('Post' => array('id' => '5', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) + array('Post' => array('id' => '5', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)), + array('Post' => array('id' => '6', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) ); $this->assertEqual($result, $expected); }