3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 669 Views |
-
update just one field of a DataObject

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 tryedbut then it overwrites the whole dog with the new one, so i need to update just that one field MyFatherID.$kid->write();
-
Re: update just one field of a DataObject

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();
| 669 Views | ||
|
Page:
1
|
Go to Top |

