Save ParentID alongside first record write to avoid validation errors

This commit is contained in:
Ingo Schommer 2015-02-15 12:07:41 +13:00
parent 4dece01c34
commit 7e8eaae73a

View File

@ -197,22 +197,31 @@ class FixtureContext extends BehatContext
*/ */
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) { public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
$class = $this->convertTypeToClass($type); $class = $this->convertTypeToClass($type);
$relationClass = $this->convertTypeToClass($relationType); $relationClass = $this->convertTypeToClass($relationType);
$obj = $this->fixtureFactory->get($class, $id);
if(!$obj) $obj = $this->fixtureFactory->createObject($class, $id);
$relationObj = $this->fixtureFactory->get($relationClass, $relationId); $relationObj = $this->fixtureFactory->get($relationClass, $relationId);
if(!$relationObj) $relationObj = $this->fixtureFactory->createObject($relationClass, $relationId); if(!$relationObj) $relationObj = $this->fixtureFactory->createObject($relationClass, $relationId);
$data = array();
if($relation == 'child') {
$data['ParentID'] = $relationObj->ID;
}
$obj = $this->fixtureFactory->get($class, $id);
if($obj) {
$obj->update($data);
$obj->write();
} else {
$obj = $this->fixtureFactory->createObject($class, $id, $data);
}
switch($relation) { switch($relation) {
case 'parent': case 'parent':
$relationObj->ParentID = $obj->ID; $relationObj->ParentID = $obj->ID;
$relationObj->write(); $relationObj->write();
break; break;
case 'child': case 'child':
$obj->ParentID = $relationObj->ID; // already written through $data above
$obj->write();
break; break;
default: default:
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(