src/Titon/Db/Repository.php
public function findID(Query $query) {
        $pk = $this->getPrimaryKey();

        // Gather ID from where clause
        foreach ($query->getWhere()->getParams() as $param) {
            if ($param instanceof Expr && $param->getField() === $pk && in_array($param->getOperator(), ['=', 'in'])) {
                return $param->getValue();
            }
        }

        // Query for the ID then
        $select = clone $query;
        $results = array_values($select->setType(Query::SELECT)->fields($pk)->lists($pk, $pk, [
            'before' => false,
            'after' => false
        ]));

        if (count($results) > 1) {
            return $results;

        } else if (count($results) === 1) {
            return $results[0];
        }

        return null;
    }
public function findID(Query $query) {
        $pk = $this->getPrimaryKey();

        // Gather ID from where clause
        foreach ($query->getWhere()->getParams() as $param) {
            if ($param instanceof Expr && $param->getField() === $pk && in_array($param->getOperator(), ['=', 'in'])) {
                return $param->getValue();
            }
        }

        // Query for the ID then
        $select = clone $query;
        $results = array_values($select->setType(Query::SELECT)->fields($pk)->lists($pk, $pk, [
            'before' => false,
            'after' => false
        ]));

        if (count($results) > 1) {
            return $results;

        } else if (count($results) === 1) {
            return $results[0];
        }

        return null;
    }
public function findID ( Query $ query ) { $ pk = $ this -> getPrimaryKey ( ) ; // Gather ID from where clause foreach ( $ query -> getWhere ( ) -> getParams ( ) as $ param ) { if ( $ param instanceof Expr && $ param -> getField ( ) === $ pk && in_array ( $ param -> getOperator ( ) , [ '=' , 'in' ] ) ) { return $ param -> getValue ( ) ; } } // Query for the ID then $ select = clone $ query ; $ results = array_values ( $ select -> setType ( Query :: SELECT ) -> fields ( $ pk ) -> lists ( $ pk , $ pk , [ 'before' => false , 'after' => false ] ) ) ; if ( count ( $ results ) > 1 ) { return $ results ; } else if ( count ( $ results ) === 1 ) { return $ results [ 0 ] ; } return null ; }
Find the a primary key value within a query. Begin by looping through the where clause and match any value
that equates to the PK field. If none can be found, do a select query for a list of IDs.

@param \Titon\Db\Query $query
@return int|int[]
Find the a primary key value within a query . Begin by looping through the where clause and match any value that equates to the PK field . If none can be found do a select query for a list of IDs .