*
* @return array Array of objects, in order
*/
- function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
+ static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls=true)
{
- $result = self::pivotGet($cls, $keyCol, $keyVals);
+ $result = self::pivotGetClass($cls, $keyCol, $keyVals);
$values = array_values($result);
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
- static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
+ static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = array())
{
if (!is_a($cls, __CLASS__, true)) {
throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
return $pkey;
}
- static function listGetClass($cls, $keyCol, $keyVals)
+ static function listFindClass($cls, $keyCol, array $keyVals)
+ {
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
+ }
+
+ $i = new $cls;
+ $i->whereAddIn($keyCol, $keyVals, $i->columnType($keyCol));
+ if (!$i->find()) {
+ throw new NoResultException($i);
+ }
+
+ sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
+ return $i;
+ }
+
+ static function listGetClass($cls, $keyCol, array $keyVals)
{
if (!is_a($cls, __CLASS__, true)) {
throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
}
if (count($allPkeys) > 0) {
- $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
+ $keyResults = self::pivotGetClass($cls, $pkeyCols, $allPkeys);
foreach ($pkeyMap as $keyVal => $pkeyList) {
foreach ($pkeyList as $pkeyVal) {
}
if (count($toFetch) > 0) {
- $i = new $cls;
- $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
- if ($i->find()) {
- sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
+ try {
+ $i = self::listFindClass($cls, $keyCol, $toFetch);
+
while ($i->fetch()) {
$copy = clone($i);
$copy->encache();
}
$pkeyMap[$i->$keyCol][] = $pkeyVal;
}
+ } catch (NoResultException $e) {
+ // no results foudn for our keyVals, so we leave them as empty arrays
}
foreach ($toFetch as $keyVal) {
self::cacheSet(sprintf("%s:list-ids:%s:%s", strtolower($cls), $keyCol, $keyVal),
/**
* @todo FIXME: Should this return false on lookup fail to match getKV?
*/
- static function pkeyGetClass($cls, $kv)
+ static function pkeyGetClass($cls, array $kv)
{
if (!is_a($cls, __CLASS__, true)) {
throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');