Created
February 24, 2014 04:41
-
-
Save wilr/9182067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dev/FixtureBlueprint.php b/dev/FixtureBlueprint.php | |
index e74bdee..3e95004 100644 | |
--- a/dev/FixtureBlueprint.php | |
+++ b/dev/FixtureBlueprint.php | |
@@ -128,27 +128,53 @@ class FixtureBlueprint { | |
// Populate all relations | |
if($data) foreach($data as $fieldName => $fieldVal) { | |
if($obj->many_many($fieldName) || $obj->has_many($fieldName)) { | |
+ $obj->write(); | |
+ | |
$parsedItems = array(); | |
- $items = preg_split('/ *, */',trim($fieldVal)); | |
- foreach($items as $item) { | |
- // Check for correct format: =><relationname>.<identifier>. | |
- // Ignore if the item has already been replaced with a numeric DB identifier | |
- if(!is_numeric($item) && !preg_match('/^=>[^\.]+\.[^\.]+/', $item)) { | |
- throw new InvalidArgumentException(sprintf( | |
- 'Invalid format for relation "%s" on class "%s" ("%s")', | |
- $fieldName, | |
- $class, | |
- $item | |
- )); | |
+ | |
+ if(is_array($fieldVal)) { | |
+ foreach($fieldVal as $relation) { | |
+ if(!isset($relation['Item'])) { | |
+ throw new InvalidArgumentException(sprintf( | |
+ 'Invalid format for relation "%s" on class "%s" ("%s") missing \'Item\' key', | |
+ $fieldName, | |
+ $class, | |
+ $item | |
+ )); | |
+ } | |
+ | |
+ $value = $this->parseValue( | |
+ $relation['Item'], $fixtures | |
+ ); | |
+ | |
+ $parsedItems[] = $value; | |
+ $extra = (isset($relation['ExtraFields'])) ? $relation['ExtraFields'] : null; | |
+ | |
+ $obj->getManyManyComponents($fieldName)->add($value, $extra); | |
+ } | |
+ } else { | |
+ $items = preg_split('/ *, */',trim($fieldVal)); | |
+ | |
+ foreach($items as $item) { | |
+ // Check for correct format: =><relationname>.<identifier>. | |
+ // Ignore if the item has already been replaced with a numeric DB identifier | |
+ if(!is_numeric($item) && !preg_match('/^=>[^\.]+\.[^\.]+/', $item)) { | |
+ throw new InvalidArgumentException(sprintf( | |
+ 'Invalid format for relation "%s" on class "%s" ("%s")', | |
+ $fieldName, | |
+ $class, | |
+ $item | |
+ )); | |
+ } | |
+ | |
+ $parsedItems[] = $this->parseValue($item, $fixtures); | |
} | |
- $parsedItems[] = $this->parseValue($item, $fixtures); | |
- } | |
- $obj->write(); | |
- if($obj->has_many($fieldName)) { | |
- $obj->getComponents($fieldName)->setByIDList($parsedItems); | |
- } elseif($obj->many_many($fieldName)) { | |
- $obj->getManyManyComponents($fieldName)->setByIDList($parsedItems); | |
+ if($obj->has_many($fieldName)) { | |
+ $obj->getComponents($fieldName)->setByIDList($parsedItems); | |
+ } elseif($obj->many_many($fieldName)) { | |
+ $obj->getManyManyComponents($fieldName)->setByIDList($parsedItems); | |
+ } | |
} | |
} elseif($obj->has_one($fieldName)) { | |
// Sets has_one with relation name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment