/** * Adds an Object to the specified relationship attribute of this Managed Object * * @param MEntityDescriptionRelationship $relationship The relationship you wish to add * an object to * @param MManagedObject $object The Managed Object to add to the relationship * @param bool $updateInverseRelationship Weather or not the inverse relationship should also be updated * * @return void */ public function addObjectToRelationship(MEntityDescriptionRelationship $relationship, MManagedObject $object, $updateInverseRelationship = true) { MAssertTypes('bool', $updateInverseRelationship); $this->fireFault(); if ($relationship->typeClassName() != $object->className()) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", $object->className(), $relationship->typeClassName())); } // Add object on this side of the relationship $arr = $this->insertedRelationships->objectForKey($relationship->name()); if (!$arr) { $arr = new MMutableArray(); $this->insertedRelationships->setObjectForKey($relationship->name(), $arr); } $arr->addObject($object); // Update the inverse side of the relationship if necessary if ($updateInverseRelationship) { $object->addObjectToRelationship($relationship->inverseRelationship(), $this, false); } }