Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

update just one field of a DataObject


Go to End
Reply


2 Posts   1687 Views

Avatar
Stefdv

Community Member, 110 Posts

19 March 2011 at 4:09am

Hello,

I have a form where a Breeder can add a Dog to the Database. In the form there is a Dropdownfield where they can choose an other dog that would be the kid of the new dog. Like Newdog is FatherOf....

Now i've come a long way ( in my opinion) but i have no idea how to update just one field in a record.



			$dogStep = $this->getSavedStepByClass('DogDetailStep');
				if($dogStep->loadData()) 
				{
			// Create the new Dog		
					$dog = new Dog();
					$dogStep->saveInto($dog);
					$dog->BreederID 	= $dog->BreederID;
					$dog->write(); 
			// New Dog is in Database
			
			// I need the ID of the just created Dog
					$thisdog = $dog->PedigreeName;
					$newDog = DataObject::get_one('Dog', "PedigreeName = '$thisdog'");
			
			
					$assignkidID = $dog->FatherOfID; 
			//FatherOfID is a field from the form where i choose which Dog is the kid.
					
					$kid = DataObject::get_one('Dog', "ID = '$assignkidID'");
			//So now i have the kid that i choose in the form.

			//Now i have to fill the field $kid->MyFatherID with $newDog->ID
					
			??????????

And that is where i'm lost. I've tryed
 $kid->write(); 
but then it overwrites the whole dog with the new one, so i need to update just that one field MyFatherID.

Avatar
Stefdv

Community Member, 110 Posts

19 March 2011 at 4:32am

Stupid me :(

I have to set the field first, and then it doesn't mather that it writes everything back, it's the same dog........duh

$kid->MyFatherID = $newDog->ID;
$kid->write();