Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #95 from fzaninotto/fix_delegate_classPrefix

[delegate behavior] Fix incorrect handling of tablePrefix
  • Loading branch information...
commit 17173eac71d797aad6b2da6736a477f2dae85ef3 2 parents 9aef5f6 + cb2009a
@willdurand willdurand authored
View
2  generator/lib/behavior/DelegateBehavior.php
@@ -36,7 +36,7 @@ public function modifyTable()
$database = $table->getDatabase();
$delegates = explode(',', $this->parameters['to']);
foreach ($delegates as $delegate) {
- $delegate = trim($delegate);
+ $delegate = $database->getTablePrefix() . trim($delegate);
if (!$database->hasTable($delegate)) {
throw new InvalidArgumentException(sprintf(
'No delegate table "%s" found for table "%s"',
View
34 test/testsuite/generator/behavior/DelegateBehaviorTest.php
@@ -233,4 +233,38 @@ public function testDelegateSimulatesMultipleClassTableInheritance()
$footballer->save(); // should not throw exception
}
+ public function testTablePrefixSameDatabase()
+ {
+ $schema = <<<EOF
+<database name="testTablePrefixSameDatabase_database" tablePrefix="foo">
+
+ <table name="testTablePrefixSameDatabase_main">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
+ <column name="title" type="VARCHAR" size="100" primaryString="true" />
+ <column name="delegate_id" type="INTEGER" />
+ <foreign-key foreignTable="testTablePrefixSameDatabase_delegate">
+ <reference local="delegate_id" foreign="id" />
+ </foreign-key>
+ <behavior name="delegate">
+ <parameter name="to" value="testTablePrefixSameDatabase_delegate" />
+ </behavior>
+ </table>
+
+ <table name="testTablePrefixSameDatabase_delegate">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
+ <column name="subtitle" type="VARCHAR" size="100" primaryString="true" />
+ </table>
+
+</database>
+EOF;
+ PropelQuickBuilder::buildSchema($schema);
+ $main = new FooTestTablePrefixSameDatabaseMain();
+ $main->setSubtitle('bar');
+ $delegate = $main->getFooTestTablePrefixSameDatabaseDelegate();
+ $this->assertInstanceOf('FooTestTablePrefixSameDatabaseDelegate', $delegate);
+ $this->assertTrue($delegate->isNew());
+ $this->assertEquals('bar', $delegate->getSubtitle());
+ $this->assertEquals('bar', $main->getSubtitle());
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.