/** * Gets an array of SaleHasProduct 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 Sale has previously been saved, it will retrieve * related SaleHasProducts from storage. If this Sale 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 SaleHasProduct[] * @throws PropelException */ public function getSaleHasProducts($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(SalePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collSaleHasProducts === null) { if ($this->isNew()) { $this->collSaleHasProducts = array(); } else { $criteria->add(SaleHasProductPeer::SALE_ID, $this->id); SaleHasProductPeer::addSelectColumns($criteria); $this->collSaleHasProducts = SaleHasProductPeer::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(SaleHasProductPeer::SALE_ID, $this->id); SaleHasProductPeer::addSelectColumns($criteria); if (!isset($this->lastSaleHasProductCriteria) || !$this->lastSaleHasProductCriteria->equals($criteria)) { $this->collSaleHasProducts = SaleHasProductPeer::doSelect($criteria, $con); } } } $this->lastSaleHasProductCriteria = $criteria; return $this->collSaleHasProducts; }
/** * Retrieve object using using composite pkey values. * @param int $sale_id * @param int $product_id * @param PropelPDO $con * @return SaleHasProduct */ public static function retrieveByPK($sale_id, $product_id, PropelPDO $con = null) { $key = serialize(array((string) $sale_id, (string) $product_id)); if (null !== ($obj = SaleHasProductPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(SaleHasProductPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(SaleHasProductPeer::DATABASE_NAME); $criteria->add(SaleHasProductPeer::SALE_ID, $sale_id); $criteria->add(SaleHasProductPeer::PRODUCT_ID, $product_id); $v = SaleHasProductPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }