Created
September 28, 2012 14:16
-
-
Save timaschew/3800132 to your computer and use it in GitHub Desktop.
patch file for using foreign keys to non pk reference (only for ManyToOne)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | |
index d73983c..9f8a253 100644 | |
--- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | |
+++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | |
@@ -598,10 +598,18 @@ class BasicEntityPersister | |
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform); | |
$this->quotedColumns[$sourceColumn] = $quotedColumn; | |
- | |
- if ($newVal === null) { | |
- $result[$owningTable][$sourceColumn] = null; | |
- } else if ($targetClass->containsForeignIdentifier) { | |
+ if ($newVal === null) { | |
+ $result[$owningTable][$sourceColumn] = null; | |
+ $this->_columnTypes[$sourceColumn] = $targetClass->getTypeOfColumn($targetColumn); | |
+ return $result; | |
+ } | |
+ // $newVal is not null | |
+ // NEW FEATURE: undefined index (foreign keys to non pk columns) | |
+ // add the real field name and value, which is used for the assoc. | |
+ // otherwise this only works if $targetColumn is the primary key and nothing else | |
+ $fieldName = $targetClass->getFieldName($targetColumn); | |
+ $newValId[$fieldName] = $targetClass->getFieldValue($newVal, $fieldName); | |
+ if ($targetClass->containsForeignIdentifier) { | |
$result[$owningTable][$sourceColumn] = $newValId[$targetClass->getFieldForColumn($targetColumn)]; | |
} else { | |
$result[$owningTable][$sourceColumn] = $newValId[$targetClass->fieldNames[$targetColumn]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a patch for one is one mapping?
Thanks.