public function export(Source $dataSource, array $options = array())
{
$defaults = array('atomic' => true);
$options += $defaults;
list($data, $nested) = $this->_exportRecursive($dataSource, $options);
if ($options['atomic'] && $this->_exists) {
$data = array_intersect_key($data, $this->_modified + $nested);
}
if ($model = $this->_model) {
$name = null;
$options = array('atomic' => false) + $options;
$relations = new Collection(array('data' => $model::relations()));
$find = function ($relation) use(&$name) {
return $relation->fieldName === $name;
};
foreach ($this->_relationships as $name => $subObject) {
if (($rel = $relations->first($find)) && $rel->link == $rel::LINK_EMBEDDED) {
$data[$name] = $subObject->export($dataSource, $options);
}
}
}
return $data;
}