From 320c30ba5de261c553bef2e794ae06c3e519cd07 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 9 Oct 2008 15:07:34 +0000 Subject: [PATCH] BUGFIX Writing record from yml before parsing relations in YamlFixture->saveIntoDatabase() to avoid missing lookups for reflexive relations on the same object git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64004 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/YamlFixture.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/model/YamlFixture.php b/core/model/YamlFixture.php index c02826644..84949f8f0 100644 --- a/core/model/YamlFixture.php +++ b/core/model/YamlFixture.php @@ -130,6 +130,12 @@ class YamlFixture extends Object { foreach($fixtureContent as $dataClass => $items) { foreach($items as $identifier => $fields) { $obj = new $dataClass(); + $obj->write(); + + // Populate the dictionary with the ID + // has to happen before relations in case a class is referring to itself + $this->fixtureDictionary[$dataClass][$identifier] = $obj->ID; + foreach($fields as $fieldName => $fieldVal) { if($obj->many_many($fieldName) || $obj->has_many($fieldName)) { $parsedItems = array(); @@ -150,9 +156,6 @@ class YamlFixture extends Object { } } $obj->write(); - - // Populate the dictionary with the ID - $this->fixtureDictionary[$dataClass][$identifier] = $obj->ID; } } }