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