From dd85ba11411b0e4fa5caa45a8cae75dddbab6a4c Mon Sep 17 00:00:00 2001
From: Andrew O'Neil <andy@andyofniall.net>
Date: Sun, 2 Dec 2007 21:27:34 +0000
Subject: [PATCH] Add an element sets the relation with the parent
 automatically but this functionnality needs to be unset for the
 HasManyComplexTablefield (merged from branches 2.2.0, r45135)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46094 467b73ca-7a2a-4603-9d3b-597d59a354a9
---
 forms/ComplexTableField.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php
index a2e4bed92..435d970dd 100755
--- a/forms/ComplexTableField.php
+++ b/forms/ComplexTableField.php
@@ -77,6 +77,8 @@ class ComplexTableField extends TableListField {
 	 */
 	protected $detailFormValidator = null;
 	
+	protected $relationAutoSetting = true;
+	
 	/**
 	 * See class comments
 	 *
@@ -100,8 +102,9 @@ class ComplexTableField extends TableListField {
 		Requirements::javascript("sapphire/javascript/ComplexTableField.js");
 		Requirements::css("jsparty/greybox/greybox.css");
 		Requirements::css("sapphire/css/ComplexTableField.css");
-
+		
 		parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
+		
 	}
 
 	function isComposite() {
@@ -258,7 +261,8 @@ JS;
 			}
 			// add relational fields
 			$detailFields->push(new HiddenField("ctf[parentClass]"," ",$this->getParentClass()));
-			$detailFields->push(new HiddenField("$parentIdName"," ",$ID));
+			if( $this->relationAutoSetting )
+				$detailFields->push(new HiddenField("$parentIdName"," ",$ID));
 		} 
 
 		// the ID field confuses the Controller-logic in finding the right view for ReferencedField
@@ -563,7 +567,7 @@ JS;
 	 * Returns the db-fieldname of the currently used has_one-relationship.
 	 */
 	function getParentIdName( $parentClass, $childClass ) {
-		return $this->getParentIdNameRelation( $parentClass, $childClass, 'has_one' );
+		return $this->getParentIdNameRelation( $childClass, $parentClass, 'has_one' );
 	}
 	
 	/**
@@ -696,7 +700,7 @@ class ComplexTableField_Popup extends Form {
 			$childObject = new $this->sourceClass();
 			$this->fields->removeByName('ID');
 		}
-
+		
 		$this->saveInto($childObject);
 		$childObject->write();