src/Sql/Manager.php
public function createKeyCriteria($meta, $id, $indexId=null)
    {
        if ($indexId == null) {
            $indexId = 'primary';
        }
        $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
        if (!isset($meta->indexes[$indexId])) {
            throw new Exception("Index $indexId does not exist on meta {$meta->id}");
        }
        $index = $meta->indexes[$indexId];
        if (!$index['key']) {
            throw new Exception("Index $indexId is not a key index for meta {$meta->id}");
        }
        if (!is_array($id)) {
            $id = array($id);
        }
        $where = array();
        
        foreach ($index['fields'] as $idx=>$p) {
            $idVal = isset($id[$p]) ? $id[$p] : (isset($id[$idx]) ? $id[$idx] : null);
            if (!$idVal) {
                throw new \InvalidArgumentException("Couldn't get ID value when getting {$meta->id} by index '{$indexId}'");
            }
            $where[$p] = $idVal;
        }
        
        return array('where'=>$where);
    }
public function createKeyCriteria($meta, $id, $indexId=null)
    {
        if ($indexId == null) {
            $indexId = 'primary';
        }
        $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
        if (!isset($meta->indexes[$indexId])) {
            throw new Exception("Index $indexId does not exist on meta {$meta->id}");
        }
        $index = $meta->indexes[$indexId];
        if (!$index['key']) {
            throw new Exception("Index $indexId is not a key index for meta {$meta->id}");
        }
        if (!is_array($id)) {
            $id = array($id);
        }
        $where = array();
        
        foreach ($index['fields'] as $idx=>$p) {
            $idVal = isset($id[$p]) ? $id[$p] : (isset($id[$idx]) ? $id[$idx] : null);
            if (!$idVal) {
                throw new \InvalidArgumentException("Couldn't get ID value when getting {$meta->id} by index '{$indexId}'");
            }
            $where[$p] = $idVal;
        }
        
        return array('where'=>$where);
    }
public function createKeyCriteria ( $ meta , $ id , $ indexId = null ) { if ( $ indexId == null ) { $ indexId = 'primary' ; } $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; if ( ! isset ( $ meta -> indexes [ $ indexId ] ) ) { throw new Exception ( "Index $indexId does not exist on meta {$meta->id}" ) ; } $ index = $ meta -> indexes [ $ indexId ] ; if ( ! $ index [ 'key' ] ) { throw new Exception ( "Index $indexId is not a key index for meta {$meta->id}" ) ; } if ( ! is_array ( $ id ) ) { $ id = array ( $ id ) ; } $ where = array ( ) ; foreach ( $ index [ 'fields' ] as $ idx => $ p ) { $ idVal = isset ( $ id [ $ p ] ) ? $ id [ $ p ] : ( isset ( $ id [ $ idx ] ) ? $ id [ $ idx ] : null ) ; if ( ! $ idVal ) { throw new \ InvalidArgumentException ( "Couldn't get ID value when getting {$meta->id} by index '{$indexId}'" ) ; } $ where [ $ p ] = $ idVal ; } return array ( 'where' => $ where ) ; }
Creates an array criteria for a key index
@param mixed $meta Meta or class name
@return array Criteria
Creates an array criteria for a key index