 			references = @constructor._references
 			for key of keys 
 				if key in _.keys(references)
-					values[key] = @validateReferenceOnSet type, key, keys[key]
+					values[key] = @validateReferenceOnSet references[key].type, key, keys[key]
 				else
 					values[key] = keys[key]
 

			# Handle dereferencing
			references = @constructor._references
			if references?
				dereferencedProperties = @_properties.withMutations (map) -> 
					for key of references
						map.set key, @dereference(key)
				val = @cache 'dereffed_props', dereferencedProperties
			else
				# No references defined, just return the props.

	validateReferenceOnSet: (type, key, value) ->
		switch type
			when 'entity'
				invariant _.isString(value) or _.isNumber(value), """
					#{@constructor.name}.set(...): #{key} must be an id for an entity on the referenced store.
					Ie. either a string or a number.
				"""
				return value
			when 'list'
				# One should never set a value for a list reference, warn.
				console.warn """
					#{@constructor.name}.set(...): #{key} is a reference to a list store.
					You can't set a value for a reference to a list store. Defaulting to null.
				"""
				return null
