/** * Selects a collection of ProductAssignment objects pre-filled with all related objects except User. * * @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 ProductAssignment objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(ProductAssignmentPeer::DATABASE_NAME); } ProductAssignmentPeer::addSelectColumns($criteria); $startcol2 = ProductAssignmentPeer::NUM_HYDRATE_COLUMNS; ProductPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS; $criteria->addJoin(ProductAssignmentPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ProductAssignmentPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ProductAssignmentPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = ProductAssignmentPeer::getOMClass(); $obj1 = new $cls(); $obj1->hydrate($row); ProductAssignmentPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Product rows $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ProductPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ProductPeer::getOMClass(); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ProductPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (ProductAssignment) to the collection in $obj2 (Product) $obj2->addProductAssignment($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Method to invalidate the instance pool of all tables related to principal * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // Invalidate objects in UserProfilePeer instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. UserProfilePeer::clearInstancePool(); // Invalidate objects in ProductPeer instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. ProductPeer::clearInstancePool(); // Invalidate objects in PrincipalI18nPeer instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. PrincipalI18nPeer::clearInstancePool(); }
/** * Adds $delta to all Rank values that are >= $first and <= $last. * '$delta' can also be negative. * * @param int $delta Value to be shifted by, can be negative * @param int $first First node to be shifted * @param int $last Last node to be shifted * @param PropelPDO $con Connection to use. */ public static function shiftRank($delta, $first = null, $last = null, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $whereCriteria = ProductQuery::create(); if (null !== $first) { $whereCriteria->add(ProductPeer::RANK_COL, $first, Criteria::GREATER_EQUAL); } if (null !== $last) { $whereCriteria->addAnd(ProductPeer::RANK_COL, $last, Criteria::LESS_EQUAL); } $valuesCriteria = new Criteria(ProductPeer::DATABASE_NAME); $valuesCriteria->add(ProductPeer::RANK_COL, array('raw' => ProductPeer::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL); BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con); ProductPeer::clearInstancePool(); }
/** * Filter the query on the unit column * * @param mixed $unit The value to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ProductQuery The current query, for fluid interface * @throws PropelException - if the value is not accepted by the enum. */ public function filterByUnit($unit = null, $comparison = null) { if (is_scalar($unit)) { $unit = ProductPeer::getSqlValueForEnum(ProductPeer::UNIT, $unit); } elseif (is_array($unit)) { $convertedValues = array(); foreach ($unit as $value) { $convertedValues[] = ProductPeer::getSqlValueForEnum(ProductPeer::UNIT, $value); } $unit = $convertedValues; if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(ProductPeer::UNIT, $unit, $comparison); }
/** * Move the object to a new rank, and shifts the rank * Of the objects inbetween the old and new rank accordingly * * @param integer $newRank rank value * @param PropelPDO $con optional connection * * @return Product the current object * * @throws PropelException */ public function moveToRank($newRank, PropelPDO $con = null) { if ($this->isNew()) { throw new PropelException('New objects cannot be moved. Please use insertAtRank() instead'); } if ($con === null) { $con = Propel::getConnection(ProductPeer::DATABASE_NAME); } if ($newRank < 1 || $newRank > ProductQuery::create()->getMaxRankArray($con)) { throw new PropelException('Invalid rank ' . $newRank); } $oldRank = $this->getSortableRank(); if ($oldRank == $newRank) { return $this; } $con->beginTransaction(); try { // shift the objects between the old and the new rank $delta = $oldRank < $newRank ? -1 : 1; ProductPeer::shiftRank($delta, min($oldRank, $newRank), max($oldRank, $newRank), $con); // move the object to its new rank $this->setSortableRank($newRank); $this->save($con); $con->commit(); return $this; } catch (Exception $e) { $con->rollback(); throw $e; } }