From 9c1202a76667d8e778a29d008a54c4ad3bda9c2e Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 19 Oct 2011 09:15:41 +0200 Subject: [PATCH] Added on generated class. This allow to unset many-to-one and one-to-one relations Example: $user->setGroup(null); --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 0792ceb91..e8ae73aee 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -117,7 +117,7 @@ public function () * @param $ * @return */ -public function ($) +public function ($) { $this-> = $; return $this; @@ -634,7 +634,7 @@ public function () foreach ($metadata->associationMappings as $associationMapping) { if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { - if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { + if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], 'null')) { $methods[] = $code; } if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { @@ -707,7 +707,7 @@ public function () return implode("\n", $lines); } - private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null) + private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) { if ($type == "add") { $addMethod = explode("\\", $typeHint); @@ -737,6 +737,7 @@ public function () '' => Inflector::camelize($fieldName), '' => $methodName, '' => $fieldName, + '' => ($defaultValue!==null?('='.$defaultValue):''), '' => $this->_getClassName($metadata) );