Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Custom column selection and use of distinct using Propel Criteria

Here is an example of obtaining a custom set of select columns using Propel Criteria, as opposed to using a custom SQL statement. The use of distinct is also demonstrated.

// Set up empty select
$c = new Criteria();
$c->clearSelectColumns();
 
// Read distinct(owningdepot) from the load table...
$c->addSelectColumn(TmsLoadPeer::OWNINGDEPOT);
$c->addGroupByColumn(TmsLoadPeer::OWNINGDEPOT);
$c->setDistinct();
 
// ...which are IN the provided list
$c->add(TmsLoadPeer::LOAD_ID, $loadIds, Criteria::IN);
$depots = TmsLoadPeer::doSelectRS($c);
 
// Then return an array of depots
$arrDep = array();
foreach ($depots as $depot)
{
  $arrDep[] = $depot[0];
}
by halfer on 2006-08-23, tagged criteria  propel 
You need to create an account or log in to post a comment or rate this snippet.