fixing bug with in-memory child objects not having their parent ID field updated via the ->add() method

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@50808 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Mark Rickerby 2008-03-10 21:48:13 +00:00
parent 5a313be83e
commit f55ba36a65

View File

@ -124,6 +124,7 @@ class ComponentSet extends DataObjectSet {
protected function loadChildIntoDatabase($item, $extraFields = null) { protected function loadChildIntoDatabase($item, $extraFields = null) {
if($this->type == '1-to-many') { if($this->type == '1-to-many') {
$child = DataObject::get_by_id($this->childClass,$item->ID); $child = DataObject::get_by_id($this->childClass,$item->ID);
if (!$child) $child = $item;
$joinField = $this->joinField; $joinField = $this->joinField;
$child->$joinField = $this->ownerObj->ID; $child->$joinField = $this->ownerObj->ID;
$child->write(); $child->write();