public function parse($object)
{
if (!is_object($object)) {
throw new ValidationException('Relationships has to be an object, "' . gettype($object) . '" given.');
}
if (property_exists($object, 'type') or property_exists($object, 'id')) {
throw new ValidationException('These properties are not allowed in attributes: `type`, `id`');
}
$object_vars = get_object_vars($object);
if (count($object_vars) === 0) {
return $this;
}
foreach ($object_vars as $name => $value) {
if ($this->parent->has('attributes.' . $name)) {
throw new ValidationException('"' . $name . '" property cannot be set because it exists already in parents Resource object.');
}
$relationship = $this->manager->getFactory()->make('Relationship', [$this->manager, $this]);
$relationship->parse($value);
$this->container->set($name, $relationship);
}
return $this;
}