public function executeDelete() { $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber'); $this->bikeid = $this->getRequestParameter('bikeid'); if ($this->getRequest()->getMethod() == sfRequest::POST) { //delete user_stat and equipment $c = new Criteria(); $c->add(UserStatsPeer::USER_ID, $userId); $c->add(UserStatsPeer::BIKE_ID, $this->bikeid); $s = UserStatsPeer::doSelectJoinAll($c); foreach ($s as $stat) { foreach ($stat->getUserStatEquips() as $equip) { $equip->delete(); } $stat->delete(); } //move equipment to shelf $c = new Criteria(); $c->add(UserEquipementPeer::USER_ID, $userId); $c->add(UserEquipementPeer::BIKE_ID, $this->bikeid); $equip = UserEquipementPeer::doSelect($c); foreach ($equip as $e) { $e->setBikeId(null); $e->save(); } //now delete bike $user_bikes = UserBikesPeer::retrieveByPk($this->bikeid); $user_bikes->delete(); return $this->redirect('userbike/index'); } }