Skip to content

Loading…

Use the parent PK type in the jointure table PK. #9

Merged
merged 2 commits into from

4 participants

@Martiusweb

EqualNestBehavior only supports primary keys of type integer.

This patch creates the schema using the type of the parent primary key.

@Martiusweb Martiusweb Use parent primary key type
Signed-off-by: Martin Richard <martius@martiusweb.net>
1e2236c
@travisbot

This pull request passes (merged 1e2236c into ed33134).

@VanTanev
Owner

Could I ask you to write a small test for this?

@Martiusweb Martiusweb Test use parent PK type
Signed-off-by: Martin Richard <martius@martiusweb.net>
5f2b77c
@willdurand
@Martiusweb

A added a commit with a test to this PR a few days ago, isn't it sufficient ?

@willdurand

Great!

@willdurand willdurand merged commit 85b91f2 into VanTanev:master

1 check passed

Details default The Travis build passed
@willdurand

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2012
  1. @Martiusweb

    Use parent primary key type

    Martiusweb committed
    Signed-off-by: Martin Richard <martius@martiusweb.net>
  2. @Martiusweb

    Test use parent PK type

    Martiusweb committed
    Signed-off-by: Martin Richard <martius@martiusweb.net>
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 2 deletions.
  1. +2 −2 src/EqualNestBehavior.php
  2. +26 −0 tests/EqualNestBehaviorTest.php
View
4 src/EqualNestBehavior.php
@@ -42,7 +42,7 @@ public function modifyTable()
$this->getTable()->addColumn(array(
'name' => $this->getReferenceColumn1Name(),
'primaryKey' => 'true',
- 'type' => 'INTEGER'
+ 'type' => $parentTablePrimaryKey[0]->getType(),
));
$fk = new ForeignKey();
@@ -58,7 +58,7 @@ public function modifyTable()
$this->getTable()->addColumn(array(
'name' => $this->getReferenceColumn2Name(),
'primaryKey' => 'true',
- 'type' => 'INTEGER',
+ 'type' => $parentTablePrimaryKey[0]->getType(),
));
$fk = new ForeignKey();
View
26 tests/EqualNestBehaviorTest.php
@@ -466,4 +466,30 @@ public function testMultiplePksInParentTableThrowsException()
XML;
$this->getBuilder($schema)->build();
}
+
+ public function testPkMatchParentPkType(){
+ $schema = <<<XML
+<database name="equal_nest_behavior_4">
+ <table name="person_4">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="BIGINT" />
+ <column name="name" type="VARCHAR" required="true" />
+ </table>
+
+ <table name="friend_4">
+ <behavior name="equal_nest">
+ <parameter name="parent_table" value="person_4" />
+ </behavior>
+ </table>
+</database>
+XML;
+ $build = $this->getBuilder($schema)->build();
+ $parentTable = new Person4TableMap();
+ $table = new Friend4TableMap();
+
+ list($parentKey) = $parentTable->getPrimaryKeyColumns();
+ $pks = $table->getPrimaryKeyColumns();
+ foreach($pks as $pk) {
+ $this->assertTrue($pk->getType() === $parentKey->getType());
+ }
+ }
}
Something went wrong with that request. Please try again.