/** * Retrieve object using using composite pkey values. * @param int $category_id * @param int $product_id * @param PropelPDO $con * @return CategoryHasProduct */ public static function retrieveByPK($category_id, $product_id, PropelPDO $con = null) { $key = serialize(array((string) $category_id, (string) $product_id)); if (null !== ($obj = CategoryHasProductPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(CategoryHasProductPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(CategoryHasProductPeer::DATABASE_NAME); $criteria->add(CategoryHasProductPeer::CATEGORY_ID, $category_id); $criteria->add(CategoryHasProductPeer::PRODUCT_ID, $product_id); $v = CategoryHasProductPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * Gets an array of CategoryHasProduct objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Category has previously been saved, it will retrieve * related CategoryHasProducts from storage. If this Category is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array CategoryHasProduct[] * @throws PropelException */ public function getCategoryHasProducts($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(CategoryPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collCategoryHasProducts === null) { if ($this->isNew()) { $this->collCategoryHasProducts = array(); } else { $criteria->add(CategoryHasProductPeer::CATEGORY_ID, $this->id); CategoryHasProductPeer::addSelectColumns($criteria); $this->collCategoryHasProducts = CategoryHasProductPeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // 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(CategoryHasProductPeer::CATEGORY_ID, $this->id); CategoryHasProductPeer::addSelectColumns($criteria); if (!isset($this->lastCategoryHasProductCriteria) || !$this->lastCategoryHasProductCriteria->equals($criteria)) { $this->collCategoryHasProducts = CategoryHasProductPeer::doSelect($criteria, $con); } } } $this->lastCategoryHasProductCriteria = $criteria; return $this->collCategoryHasProducts; }