public function build($overrides = array(), $associated = array())
{
$data = $this->_defaults;
if ($associated) {
foreach ($associated as $name => $document) {
if (!isset($this->_associations[$name])) {
throw new \Exception("No association '{$name}' defined");
}
$association = $this->_associations[$name];
if (!$association instanceof Association\EmbedsMany && !$association instanceof Association\EmbedsOne) {
throw new \Exception("Invalid association object for '{$name}'");
}
$overrides[$name] = $document;
}
}
$this->_evalSequence($data);
if ($overrides) {
foreach ($overrides as $field => $value) {
$data[$field] = $value;
}
}
return $data;
}