This commit is contained in:
parent
69c8531deb
commit
422890ceb0
@ -80,9 +80,21 @@ class Doctrine_Export_Pgsql_TestCase extends Doctrine_UnitTestCase
|
||||
public function testExportSql()
|
||||
{
|
||||
$sql = $this->export->exportSql(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
|
||||
|
||||
print "<pre>";
|
||||
print_r($sql);
|
||||
$this->assertEqual($sql, array ( 0 => 'CREATE TABLE foo (id BIGSERIAL, name VARCHAR(200) NOT NULL, parent_id BIGINT, local_foo BIGINT, PRIMARY KEY(id))',
|
||||
1 => 'CREATE TABLE foo_reference (foo1 BIGINT, foo2 BIGINT, PRIMARY KEY(foo1, foo2))',
|
||||
2 => 'CREATE TABLE foo_bar_record (fooid BIGINT, barid BIGINT, PRIMARY KEY(fooid, barid))',
|
||||
3 => 'CREATE TABLE bar (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))',
|
||||
4 => 'CREATE TABLE foo_locally_owned (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))',
|
||||
5 => 'CREATE TABLE foo_foreignly_owned (id BIGSERIAL, name VARCHAR(200), fooid BIGINT, PRIMARY KEY(id))',
|
||||
6 => 'CREATE TABLE foo_foreignly_owned_with_pk (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))',
|
||||
7 => 'ALTER TABLE foo_reference ADD CONSTRAINT FOREIGN KEY (foo1) REFERENCES foo(id) ON DELETE CASCADE',
|
||||
8 => 'ALTER TABLE foo_reference ADD CONSTRAINT FOREIGN KEY (foo2) REFERENCES foo(id) ON DELETE CASCADE',
|
||||
9 => 'ALTER TABLE foo ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES foo(id) ON DELETE CASCADE',
|
||||
10 => 'ALTER TABLE foo_foreignly_owned_with_pk ADD CONSTRAINT FOREIGN KEY (id) REFERENCES foo(id)',
|
||||
11 => 'ALTER TABLE foo_bar_record ADD CONSTRAINT FOREIGN KEY (fooId) REFERENCES foo(id)',
|
||||
12 => 'ALTER TABLE foo_bar_record ADD CONSTRAINT FOREIGN KEY (barId) REFERENCES bar(id)',
|
||||
13 => 'ALTER TABLE foo_bar_record ADD CONSTRAINT FOREIGN KEY (barId) REFERENCES bar(id)',
|
||||
14 => 'ALTER TABLE foo_bar_record ADD CONSTRAINT FOREIGN KEY (fooId) REFERENCES foo(id)', ));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -33,23 +33,40 @@ class FooRecord extends Doctrine_Record
|
||||
$this->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
|
||||
$this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true));
|
||||
$this->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
|
||||
$this->hasMany('BarRecord as Bar', array('local' => 'fooId', 'foreign' => 'barId', 'refClass' => 'FooBarRecord'));
|
||||
|
||||
}
|
||||
}
|
||||
class FooReferenceRecord extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->setTableName('foo_reference');
|
||||
|
||||
$this->hasColumn('foo1', 'integer', null, array('primary' => true));
|
||||
$this->hasColumn('foo2', 'integer', null, array('primary' => true));
|
||||
}
|
||||
}
|
||||
|
||||
class FooBarRecord extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->hasColumn('fooId', 'integer', null, array('primary' => true));
|
||||
$this->hasColumn('barId', 'integer', null, array('primary' => true));
|
||||
$this->hasColumn('fooId', 'integer', null, array('primary' => true));
|
||||
$this->hasColumn('barId', 'integer', null, array('primary' => true));
|
||||
}
|
||||
}
|
||||
class BarRecord extends Doctrine_Record
|
||||
class BarRecord extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->setTableName('bar');
|
||||
$this->hasColumn('name', 'string', 200);
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
$this->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord'));
|
||||
}
|
||||
}
|
||||
class FooLocallyOwned extends Doctrine_Record
|
||||
{
|
||||
@ -77,13 +94,4 @@ class FooForeignlyOwnedWithPk extends Doctrine_Record
|
||||
$this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id'));
|
||||
}
|
||||
}
|
||||
class FooReferenceRecord extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->setTableName('foo_reference');
|
||||
|
||||
$this->hasColumn('foo1', 'integer', null, array('primary' => true));
|
||||
$this->hasColumn('foo2', 'integer', null, array('primary' => true));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user