public function save($name = null) { if (is_null($name)) { foreach ($this->relations as $name => $relation) { try { $relation->saveAll(); } catch (DataModel\Relation\Exception\SaveNotSupported $e) { // We don't care if a relation doesn't support saving } } } else { if (!isset($this->relations[$name])) { throw new DataModel\Relation\Exception\RelationNotFound("Relation '{$name}' not found"); } $this->relations[$name]->saveAll(); } return $this->parentModel; }