/** * This function checks the local equal nest collection against the database * and creates new relations or deletes ones that have been removed * * @param PropelPDO $con */ public function processEqualNestQueries(PropelPDO $con = null) { if (false === $this->alreadyInEqualNestProcessing && null !== $this->collEqualNestFriends) { if (null === $con) { $con = Propel::getConnection(PersonPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $this->alreadyInEqualNestProcessing = true; $this->clearListFriendsPKs(); $this->initListFriendsPKs($con); $this->collEqualNestFriends->save(); $con->beginTransaction(); try { foreach ($this->getFriends()->getPrimaryKeys($usePrefix = false) as $columnKey => $pk) { if (!in_array($pk, $this->listEqualNestFriendsPKs)) { // save new equal nest relation FriendPeer::buildEqualNestFriendRelation($this, $pk, $con); // add this object to the sibling's collection $this->getFriends()->get($columnKey)->addFriend($this); } else { // remove the pk from the list of db keys unset($this->listEqualNestFriendsPKs[array_search($pk, $this->listEqualNestFriendsPKs)]); } } // if we have keys still left, this means they are relations that have to be removed foreach ($this->listEqualNestFriendsPKs as $oldPk) { FriendPeer::removeEqualNestFriendRelation($this, $oldPk, $con); } $con->commit(); $this->alreadyInEqualNestProcessing = false; } catch (PropelException $e) { $con->rollBack(); throw $e; } } }