From 54e5f45c6183b0917c7c6a802b0f7d738fe2776d Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 9 Jul 2007 11:06:49 +0000 Subject: [PATCH] --- lib/Doctrine/Export/Sqlite.php | 9 ++++--- tests/Relation/OneToManyTestCase.php | 35 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/Export/Sqlite.php b/lib/Doctrine/Export/Sqlite.php index daf2ce2e6..7fd7389d7 100644 --- a/lib/Doctrine/Export/Sqlite.php +++ b/lib/Doctrine/Export/Sqlite.php @@ -179,15 +179,14 @@ class Doctrine_Export_Sqlite extends Doctrine_Export $queryFields.= ', PRIMARY KEY('.implode(', ', array_values($options['primary'])).')'; } + $name = $this->conn->quoteIdentifier($name, true); + $query[] = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; + if (isset($options['indexes']) && ! empty($options['indexes'])) { foreach ($options['indexes'] as $index => $definition) { - $queryFields .= ', ' . $this->getIndexDeclaration($index, $definition); + $query[] = $this->createIndexSql($name, $index, $definition); } } - - $name = $this->conn->quoteIdentifier($name, true); - $query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; - return $query; diff --git a/tests/Relation/OneToManyTestCase.php b/tests/Relation/OneToManyTestCase.php index 0c239d7c8..bfc0d5413 100644 --- a/tests/Relation/OneToManyTestCase.php +++ b/tests/Relation/OneToManyTestCase.php @@ -34,7 +34,12 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase { public function prepareData() { } - + public function prepareTables() + { + $this->tables = array('Entity', 'Phonenumber', 'Email', 'Policy', 'PolicyAsset'); + + parent::prepareTables(); + } public function testRelationParsing() { $table = $this->conn->getTable('Entity'); @@ -47,7 +52,7 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase $this->assertTrue($rel instanceof Doctrine_Relation_LocalKey); } - + public function testRelationParsing2() { $table = $this->conn->getTable('Phonenumber'); @@ -66,6 +71,19 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase $this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey); } public function testRelationSaving() + { + $p = new Policy(); + $p->policy_number = '123'; + + $a = new PolicyAsset(); + $a->value = '123.13'; + + $p->PolicyAssets[] = $a; + $p->save(); + + $this->assertEqual($a->policy_number, '123'); + } + public function testRelationSaving2() { $e = new Entity(); $e->name = 'test'; @@ -79,8 +97,8 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase } class Policy extends Doctrine_Record { - public function setTableDefinition(){ - $this->setTableName('policies'); + public function setTableDefinition() + { $this->hasColumn('policy_number', 'integer', 11, array('unique' => true)); } @@ -88,22 +106,21 @@ class Policy extends Doctrine_Record { $this->hasMany('PolicyAsset as PolicyAssets', array('local' => 'policy_number', 'foreign' => 'policy_number')); - $this->index('policy_number_index', array('fields' => 'policy_number')); + $this->index('policy_number_index', array('fields' => array('policy_number'))); } } class PolicyAsset extends Doctrine_Record { public function setTableDefinition() { - $this->setTableName('policy_assets'); $this->hasColumn('policy_number', 'integer', 11); $this->hasColumn('value', 'float', 10, array ('notblank' => true,)); } - public function setUp(){ + public function setUp() + { $this->hasOne('Policy', array('foreign' => 'policy_number', 'local' => 'policy_number')); - $this->index('policy_number_index', array('fields' => 'policy_number')); - $this->index('vehicle_code_index', array('fields' => 'vehicle_code')); + $this->index('policy_number_index', array('fields' => array('policy_number'))); } }