public function saveUserHasRoleList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['user_has_role_list'])) { // somebody has unset this widget return; } if (is_null($con)) { $con = $this->getConnection(); } $c = new Criteria(); $c->add(UserHasRolePeer::ROLE_ID, $this->object->getPrimaryKey()); UserHasRolePeer::doDelete($c, $con); $values = $this->getValue('user_has_role_list'); if (is_array($values)) { foreach ($values as $value) { $obj = new UserHasRole(); $obj->setRoleId($this->object->getPrimaryKey()); $obj->setUserId($value); $obj->save(); } } }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { foreach (sfMixer::getCallables('BaseUserHasRole:delete:pre') as $callable) { $ret = call_user_func($callable, $this, $con); if ($ret) { return; } } if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(UserHasRolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { UserHasRolePeer::doDelete($this, $con); $this->setDeleted(true); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } foreach (sfMixer::getCallables('BaseUserHasRole:delete:post') as $callable) { call_user_func($callable, $this, $con); } }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = RolePeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related UserHasRole objects $c = new Criteria(UserHasRolePeer::DATABASE_NAME); $c->add(UserHasRolePeer::ROLE_ID, $obj->getId()); $affectedRows += UserHasRolePeer::doDelete($c, $con); } return $affectedRows; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = UserPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::RECIPIENT_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::SENDER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::OWNER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::USER_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related ReservationOtherMembers objects $c = new Criteria(ReservationOtherMembersPeer::DATABASE_NAME); $c->add(ReservationOtherMembersPeer::USER_ID, $obj->getId()); $affectedRows += ReservationOtherMembersPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::USER_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); // delete related UsergroupHasChief objects $c = new Criteria(UsergroupHasChiefPeer::DATABASE_NAME); $c->add(UsergroupHasChiefPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasChiefPeer::doDelete($c, $con); // delete related UsergroupHasUser objects $c = new Criteria(UsergroupHasUserPeer::DATABASE_NAME); $c->add(UsergroupHasUserPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasUserPeer::doDelete($c, $con); // delete related UserHasRole objects $c = new Criteria(UserHasRolePeer::DATABASE_NAME); $c->add(UserHasRolePeer::USER_ID, $obj->getId()); $affectedRows += UserHasRolePeer::doDelete($c, $con); } return $affectedRows; }