/** * 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 = CardPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::CARD_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::CARD_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); } return $affectedRows; }
/** * 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('BaseReservation: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(ReservationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { ReservationPeer::doDelete($this, $con); $this->setDeleted(true); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } foreach (sfMixer::getCallables('BaseReservation: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 = ActivityPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related ActivityHasFeature objects $c = new Criteria(ActivityHasFeaturePeer::DATABASE_NAME); $c->add(ActivityHasFeaturePeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ActivityHasFeaturePeer::doDelete($c, $con); // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related Reservationreason objects $c = new Criteria(ReservationreasonPeer::DATABASE_NAME); $c->add(ReservationreasonPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ReservationreasonPeer::doDelete($c, $con); // delete related RoomHasActivity objects $c = new Criteria(RoomHasActivityPeer::DATABASE_NAME); $c->add(RoomHasActivityPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += RoomHasActivityPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); // delete related UsergroupHasActivity objects $c = new Criteria(UsergroupHasActivityPeer::DATABASE_NAME); $c->add(UsergroupHasActivityPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += UsergroupHasActivityPeer::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; }