case 'document':
if (!
$model instanceof Document
) { throw new RuntimeException(sprintf('Model object is not an instance of expected class "%s"', Document::
class));
} if (!
empty($data['id'
])) { $elements =
new ArrayCollection();
foreach ($data['elements'
] as $element) { $elementModel =
$this->
getRepository('documentElement'
)->
find($element['id'
]);
if (!
$elementModel instanceof DocumentElement
) { $elementModel =
new DocumentElement();
$elementModel->
setDocument($model);
} $elementModel->
fromArray($element);
$elements->
add($elementModel);
} $data['elements'
] =
$elements;
} else { $data['elements'
] =
$this->
createDocumentElements($model);
} break;