Added ID,ID,ID syntax for populating many-many joins

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40420 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2007-08-17 05:43:14 +00:00
parent ff00abd449
commit c04c8f1a5c

View File

@ -117,14 +117,16 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
foreach($items as $identifier => $fields) {
$obj = new $dataClass();
foreach($fields as $fieldName => $fieldVal) {
// Parse a dictionary reference - used to set foreign keys
if(substr($fieldVal,0,2) == '=>') {
list($a, $b) = explode('.', substr($fieldVal,2), 2);
$obj->$fieldName = $this->fixtureDictionary[$a][$b];
if($obj->many_many($fieldName)) {
$items = split(' *, *',trim($fieldVal));
foreach($items as $item) {
$parsedItems[] = $this->parseFixtureVal($item);
}
$obj->write();
$obj->$fieldName()->setByIdList($parsedItems);
// Regular field value setting
} else {
$obj->$fieldName = $fieldVal;
$obj->$fieldName = $this->parseFixtureVal($fieldVal);
}
}
$obj->write();
@ -135,6 +137,21 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
}
}
/**
* Parse a value from a fixture file. If it starts with => it will get an ID from the fixture dictionary
*/
protected function parseFixtureVal($fieldVal) {
// Parse a dictionary reference - used to set foreign keys
if(substr($fieldVal,0,2) == '=>') {
list($a, $b) = explode('.', substr($fieldVal,2), 2);
return $this->fixtureDictionary[$a][$b];
// Regular field value setting
} else {
return $fieldVal;
}
}
function tearDown() {
// Delete our temporary database
$dbConn = DB::getConn();