index.js
function(ref) {
            var keys = ref.split('.'),
                key = keys.shift(),
                result = _this.result[key];

            if(!result) {
                // If the result does not exist, return an empty
                throw new TypeError('Could not read property \'' + key + '\' from undefined');
            }

            // Iterate over all the keys and find the property
            while((key = keys.shift())) {
                result = result[key];
            }

            if(_.isObject(result) && !_.isArray(result)) {
                // Test if the result we have is an object. This means the user wants to reference
                // to the _id of the object.
                if(!result._id) {
                    // If no _id property exists, throw a TypeError that the property could not be found
                    throw new TypeError('Could not read property \'_id\' of ' + JSON.stringify(result));
                }

                return result._id;
            }

            return result;
        }
function(ref) {
            var keys = ref.split('.'),
                key = keys.shift(),
                result = _this.result[key];

            if(!result) {
                // If the result does not exist, return an empty
                throw new TypeError('Could not read property \'' + key + '\' from undefined');
            }

            // Iterate over all the keys and find the property
            while((key = keys.shift())) {
                result = result[key];
            }

            if(_.isObject(result) && !_.isArray(result)) {
                // Test if the result we have is an object. This means the user wants to reference
                // to the _id of the object.
                if(!result._id) {
                    // If no _id property exists, throw a TypeError that the property could not be found
                    throw new TypeError('Could not read property \'_id\' of ' + JSON.stringify(result));
                }

                return result._id;
            }

            return result;
        }
function ( ref ) { var keys = ref . split ( '.' ) , key = keys . shift ( ) , result = _this . result [ key ] ; if ( ! result ) { // If the result does not exist, return an empty throw new TypeError ( 'Could not read property \'' + key + '\' from undefined' ) ; } // Iterate over all the keys and find the property while ( ( key = keys . shift ( ) ) ) { result = result [ key ] ; } if ( _ . isObject ( result ) && ! _ . isArray ( result ) ) { // Test if the result we have is an object. This means the user wants to reference // to the _id of the object. if ( ! result . _id ) { // If no _id property exists, throw a TypeError that the property could not be found throw new TypeError ( 'Could not read property \'_id\' of ' + JSON . stringify ( result ) ) ; } return result . _id ; } return result ; }
This method searches for the _id associated with the object represented
by the reference provided.

@param  {String} ref The string representation of the reference.
@return {String}     The reference to the object.
This method searches for the _id associated with the object represented by the reference provided .