/** * 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 ChildCurrency A model object, or null if the key is not found */ protected function findPkSimple($key, ConnectionInterface $con) { $sql = 'SELECT `id`, `numeric`, `alpha_3`, `name`, `symbol_left`, `symbol_right`, `decimal_digits`, `sub_divisor`, `sub_symbol_left`, `sub_symbol_right` FROM `kk_currency` WHERE `id` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, 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 ChildCurrency $obj */ $obj = new ChildCurrency(); $obj->hydrate($row); CurrencyTableMap::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * Performs a DELETE on the database, given a Currency or Criteria object OR a primary key value. * * @param mixed $values Criteria or Currency 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(CurrencyTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \keeko\core\model\Currency) { // 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(CurrencyTableMap::DATABASE_NAME); $criteria->add(CurrencyTableMap::COL_ID, (array) $values, Criteria::IN); } $query = CurrencyQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { CurrencyTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { CurrencyTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
/** * 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['Currency'][$this->hashCode()])) { return '*RECURSION*'; } $alreadyDumpedObjects['Currency'][$this->hashCode()] = true; $keys = CurrencyTableMap::getFieldNames($keyType); $result = array($keys[0] => $this->getId(), $keys[1] => $this->getNumeric(), $keys[2] => $this->getAlpha3(), $keys[3] => $this->getName(), $keys[4] => $this->getSymbolLeft(), $keys[5] => $this->getSymbolRight(), $keys[6] => $this->getDecimalDigits(), $keys[7] => $this->getSubDivisor(), $keys[8] => $this->getSubSymbolLeft(), $keys[9] => $this->getSubSymbolRight()); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->collCountries) { switch ($keyType) { case TableMap::TYPE_CAMELNAME: $key = 'countries'; break; case TableMap::TYPE_FIELDNAME: $key = 'kk_countries'; break; default: $key = 'Countries'; } $result[$key] = $this->collCountries->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } return $result; }