public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($Advice = AdvicePeer::retrieveByPk($request->getParameter('id')), sprintf('Object Advice does not exist (%s).', $request->getParameter('id'))); $Advice->delete(); $this->redirect('advice/index'); }
/** * Get the associated Advice object * * @param PropelPDO Optional Connection object. * @return Advice The associated Advice object. * @throws PropelException */ public function getAdvice(PropelPDO $con = null) { if ($this->aAdvice === null && $this->advice_id !== null) { $this->aAdvice = AdvicePeer::retrieveByPk($this->advice_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAdvice->addImagess($this); */ } return $this->aAdvice; }
/** * Selects a collection of Tags objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of Tags objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } TagsPeer::addSelectColumns($criteria); $startcol2 = TagsPeer::NUM_COLUMNS - TagsPeer::NUM_LAZY_LOAD_COLUMNS; AdvicePeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (AdvicePeer::NUM_COLUMNS - AdvicePeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(TagsPeer::ADVICE_ID, AdvicePeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseTagsPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = TagsPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = TagsPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = TagsPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); TagsPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Advice rows $key2 = AdvicePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = AdvicePeer::getInstanceFromPool($key2); if (!$obj2) { $cls = AdvicePeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); AdvicePeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (Tags) to the collection in $obj2 (Advice) $obj2->addTags($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * 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 = sfGuardUserPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related sfGuardUserProfile objects $criteria = new Criteria(sfGuardUserProfilePeer::DATABASE_NAME); $criteria->add(sfGuardUserProfilePeer::USER_ID, $obj->getId()); $affectedRows += sfGuardUserProfilePeer::doDelete($criteria, $con); // delete related Advice objects $criteria = new Criteria(AdvicePeer::DATABASE_NAME); $criteria->add(AdvicePeer::USER_ID, $obj->getId()); $affectedRows += AdvicePeer::doDelete($criteria, $con); // delete related sfGuardUserPermission objects $criteria = new Criteria(sfGuardUserPermissionPeer::DATABASE_NAME); $criteria->add(sfGuardUserPermissionPeer::USER_ID, $obj->getId()); $affectedRows += sfGuardUserPermissionPeer::doDelete($criteria, $con); // delete related sfGuardUserGroup objects $criteria = new Criteria(sfGuardUserGroupPeer::DATABASE_NAME); $criteria->add(sfGuardUserGroupPeer::USER_ID, $obj->getId()); $affectedRows += sfGuardUserGroupPeer::doDelete($criteria, $con); // delete related sfGuardRememberKey objects $criteria = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME); $criteria->add(sfGuardRememberKeyPeer::USER_ID, $obj->getId()); $affectedRows += sfGuardRememberKeyPeer::doDelete($criteria, $con); } return $affectedRows; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = AdvicePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setSlug($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setRating($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDescription($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setInstruction($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setCreatedAt($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setActive($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setMovie($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setLevel($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setVisited($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setTitle($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setCategoryId($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setCategoryUpcategoryId($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setUserId($arr[$keys[13]]); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Categories is new, it will return * an empty collection; or if this Categories has previously * been saved, it will retrieve related AdvicesRelatedByCategoryUpcategoryId from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Categories. */ public function getAdvicesRelatedByCategoryUpcategoryIdJoinsfGuardUser($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(CategoriesPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collAdvicesRelatedByCategoryUpcategoryId === null) { if ($this->isNew()) { $this->collAdvicesRelatedByCategoryUpcategoryId = array(); } else { $criteria->add(AdvicePeer::CATEGORY_UPCATEGORY_ID, $this->categoryup_id); $this->collAdvicesRelatedByCategoryUpcategoryId = AdvicePeer::doSelectJoinsfGuardUser($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(AdvicePeer::CATEGORY_UPCATEGORY_ID, $this->categoryup_id); if (!isset($this->lastAdviceRelatedByCategoryUpcategoryIdCriteria) || !$this->lastAdviceRelatedByCategoryUpcategoryIdCriteria->equals($criteria)) { $this->collAdvicesRelatedByCategoryUpcategoryId = AdvicePeer::doSelectJoinsfGuardUser($criteria, $con, $join_behavior); } } $this->lastAdviceRelatedByCategoryUpcategoryIdCriteria = $criteria; return $this->collAdvicesRelatedByCategoryUpcategoryId; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(AdvicePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(AdvicePeer::DATABASE_NAME); $criteria->add(AdvicePeer::ID, $pks, Criteria::IN); $objs = AdvicePeer::doSelect($criteria, $con); } return $objs; }
/** * Method to invalidate the instance pool of all tables related to categories * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // invalidate objects in AdvicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. AdvicePeer::clearInstancePool(); // invalidate objects in AdvicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. AdvicePeer::clearInstancePool(); }