 <cffunction name="validatesPresenceOf" returntype="void" access="public" output="false" hint="Validates that the specified property exists and that its value is not blank."
 	examples=
 	'
-		<!--- In models/User.cfc --->
-		<cffunction name="init">
-			<!--- Make sure that the user data can not be saved to the database without the `emailAddress` property --->
-  			<cfset validatesPresenceOf(property="emailAddress", message="You forgot to enter your email address!")>
-		</cffunction>
+		<!--- Make sure that the user data can not be saved to the database without the `emailAddress` property (it has to exist and not be an empty string) --->
+		<cfset validatesPresenceOf("emailAddress")>
 	'
 	categories="model-initialization,validation" chapters="object-validation" functions="validatesConfirmationOf,validatesExclusionOf,validatesFormatOf,validatesInclusionOf,validatesLengthOf,validatesNumericalityOf,validatesUniquenessOf">
 	<cfargument name="properties" type="string" required="false" default="" hint="See documentation for @validatesConfirmationOf.">

	</cfscript>
</cffunction>

<cffunction name="validatesLengthOf" returntype="void" access="public" output="false" hint="Validates that the value of the specified property matches the length requirements supplied. Only one of the `exactly`, `maximum`, `minimum` and `within` arguments can be used at a time."
	examples=
	'
		<!--- In models/User.cfc --->
		<cffunction name="init">
			<!--- Make sure that the username chosen is not more than 50 characters --->
  			<cfset validatesLengthOf(property="username", maximum=50, message="Please limit your username to 50 characters please.")>
		</cffunction>
	'
	categories="model-initialization,validation" chapters="object-validation" functions="validatesConfirmationOf,validatesExclusionOf,validatesFormatOf,validatesInclusionOf,validatesNumericalityOf,validatesPresenceOf,validatesUniquenessOf">
	<cfargument name="properties" type="string" required="false" default="" hint="See documentation for @validatesConfirmationOf.">

<cffunction name="$validateUniquenessOf" returntype="void" access="public" output="false" hint="Adds an error if the object property fail to pass the validation setup in the @validatesUniquenessOf method.">
	<cfscript>
		var loc = {};
		
		// create the WHERE clause to be used in the query that checks if an identical value already exists
		// wrap value in single quotes unless it's numeric
		// example: "userName='Joe'"
		loc.where = arguments.property & "=";
		if (!IsNumeric(this[arguments.property]))
			loc.where = loc.where & "'";
		loc.where = loc.where & this[arguments.property];
		if (!IsNumeric(this[arguments.property]))
			loc.where = loc.where & "'";
		
		// add scopes to the WHERE clause if passed in, this means that checks for other properties are done in the WHERE clause as well
		// example: "userName='Joe'" becomes "userName='Joe' AND account=1" if scope is "account" for example
		if (Len(arguments.scope))
		{
			loc.iEnd = ListLen(arguments.scope);
			for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
			{
				loc.where = loc.where & " AND ";
				loc.property = Trim(ListGetAt(arguments.scope, loc.i));
				loc.where = loc.where & loc.property & "=";
				if (!IsNumeric(this[loc.property]))
					loc.where = loc.where & "'";
				loc.where = loc.where & this[loc.property];
				if (!IsNumeric(this[loc.property]))
					loc.where = loc.where & "'";
			}
		}
		
		// try to fetch existing object from the database
		loc.existingObject = findOne(where=loc.where, reload=true);

		// we add an error if an object was found in the database and the current object is either not saved yet or not the same as the one in the database
		if (IsObject(loc.existingObject) && (isNew() || loc.existingObject.key() != key($persisted=true)))
			addError(property=arguments.property, message=arguments.message);
	</cfscript>
