public function setModelRelationship(&$model, Field $field)
    {
        //if this is a belongsToMany, we want to sort our initial values
        $relatedItems   = $this->getModelRelatedItems($model, $field);
        $name           = $field->getOption('field_name');
        $multipleValues = $field->getOption('multiple_values');
        $nameField      = $field->getOption('name_field');
        $autocomplete   = $field->getOption('autocomplete');
        $options        = $field->getOption('options');

        //get all existing values for this relationship
        if ($relatedItems) {
            //the array that holds all the ids of the currently-related items
            $relationsArray = array();

            //the id-indexed array that holds all of the select option data for a relation.
            //this holds the currently-related items and all of the available options
            $autocompleteArray = array();

            //iterate over the items
            foreach ($relatedItems as $item) {
                $keyName = $item->getKeyName();

                //if this is a mutliple-value type (i.e. HasMany, BelongsToMany), make sure this is an array
                if ($multipleValues) {
                    $relationsArray[] = $item->{$keyName};
                } else {
                    $model->setAttribute($name, $item->{$keyName});
                }

                //if this is an autocomplete field, we'll need to provide an array of arrays with 'id' and 'text' indexes
                if ($autocomplete) {
                    $autocompleteArray[$item->{$keyName}] = array('id' => $item->{$keyName}, 'text' => $item->{$nameField});
                }
            }

            //if this is a BTM, set the relations array to the property that matches the relationship name
            if ($multipleValues) {
                $model->{$name} = $relationsArray;
            }

            //set the options attribute
            $model->setAttribute($name.'_options', $options);

            //unset the relationships so we only get back what we need
            $model->relationships = array();

            //set the autocomplete array
            if ($autocomplete) {
                $model->setAttribute($name.'_autocomplete', $autocompleteArray);
            }
        }
        //if there are no values, then just set an empty array
        else {
            $model->{$name} = array();
        }
    }