/** * Performs a DELETE on the database, given a PermissionGroupPermission or Criteria object OR a primary key value. * * @param mixed $values Criteria or PermissionGroupPermission object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows * if supported by native driver or if emulated using Propel. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(PermissionGroupPermissionTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \Tekstove\ApiBundle\Model\Acl\PermissionGroupPermission) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(PermissionGroupPermissionTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { // array is not multi-dimensional $values = array($values); } foreach ($values as $value) { $criterion = $criteria->getNewCriterion(PermissionGroupPermissionTableMap::COL_GROUP_ID, $value[0]); $criterion->addAnd($criteria->getNewCriterion(PermissionGroupPermissionTableMap::COL_PERMISSION_ID, $value[1])); $criteria->addOr($criterion); } } $query = PermissionGroupPermissionQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { PermissionGroupPermissionTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { PermissionGroupPermissionTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
/** * Initializes the collPermissionGroupPermissions collection. * * By default this just sets the collPermissionGroupPermissions collection to an empty array (like clearcollPermissionGroupPermissions()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @param boolean $overrideExisting If set to true, the method call initializes * the collection even if it is not empty * * @return void */ public function initPermissionGroupPermissions($overrideExisting = true) { if (null !== $this->collPermissionGroupPermissions && !$overrideExisting) { return; } $collectionClassName = PermissionGroupPermissionTableMap::getTableMap()->getCollectionClassName(); $this->collPermissionGroupPermissions = new $collectionClassName(); $this->collPermissionGroupPermissions->setModel('\\Tekstove\\ApiBundle\\Model\\Acl\\PermissionGroupPermission'); }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildPermissionGroupPermission A model object, or null if the key is not found */ protected function findPkSimple($key, ConnectionInterface $con) { $sql = 'SELECT `group_id`, `permission_id` FROM `permission_group_permission` WHERE `group_id` = :p0 AND `permission_id` = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); } $obj = null; if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { /** @var ChildPermissionGroupPermission $obj */ $obj = new ChildPermissionGroupPermission(); $obj->hydrate($row); PermissionGroupPermissionTableMap::addInstanceToPool($obj, serialize([null === $key[0] || is_scalar($key[0]) || is_callable([$key[0], '__toString']) ? (string) $key[0] : $key[0], null === $key[1] || is_scalar($key[1]) || is_callable([$key[1], '__toString']) ? (string) $key[1] : $key[1]])); } $stmt->closeCursor(); return $obj; }
/** * Exports the object as an array. * * You can specify the key type of the array by passing one of the class * type constants. * * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. * Defaults to TableMap::TYPE_PHPNAME. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. * * @return array an associative array containing the field names (as keys) and field values */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['PermissionGroupPermission'][$this->hashCode()])) { return '*RECURSION*'; } $alreadyDumpedObjects['PermissionGroupPermission'][$this->hashCode()] = true; $keys = PermissionGroupPermissionTableMap::getFieldNames($keyType); $result = array($keys[0] => $this->getGroupId(), $keys[1] => $this->getPermissionId()); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aPermissionGroup) { switch ($keyType) { case TableMap::TYPE_CAMELNAME: $key = 'permissionGroup'; break; case TableMap::TYPE_FIELDNAME: $key = 'permission_group'; break; default: $key = 'PermissionGroup'; } $result[$key] = $this->aPermissionGroup->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->aPermission) { switch ($keyType) { case TableMap::TYPE_CAMELNAME: $key = 'permission'; break; case TableMap::TYPE_FIELDNAME: $key = 'permission'; break; default: $key = 'Permission'; } $result[$key] = $this->aPermission->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } } return $result; }