public function __construct(model_relation $relation) { if (!$relation) { throw new \InvalidArgumentException('missing relation'); } $this->relationName = $relation->getName(); if (is_null($this->relationName)) { // relation's name is considered equivalent to some property of starting node's model throw new \InvalidArgumentException('relation must be named for editing'); } // check if relation's binding makes it suitable for editing here // (there must be exactly one unbound reference in relation now) $unboundReferences = $relation->getUnboundReferences(); switch (count($unboundReferences)) { case 1: break; case 2: if ($unboundReferences[0] === $relation->referenceAtIndex(0)) { // first reference might be also unbound due to item not // selected yet // -> ignore ... array_shift($unboundReferences); break; } default: throw new \InvalidArgumentException('relation is not properly bound for editing'); } // store information $this->relation = $relation; $this->mutable = array_shift($unboundReferences); // also take snapshot of relation's initial binding state $this->initialBinding = model_relation_binding::createOnRelation($relation)->save(); }