Weird ColdFusion 9 ORM Error
- October 27, 2009 5:32 PM
- ColdFusion, Mystery Error Message
- Comments (5)
I'm trying to get a feel for the new ColdFusion 9 ORM setup, and I ran into an error message that I'd not seen before stating that "[Macromedia][SQLServer JDBC Driver][SQLServer]'FK3498A0CE621DF1' is not a constraint." This isn't too daunting, since I'm used to weird SQL errors, but when I refreshed the error I got back "[Macromedia][SQLServer JDBC Driver][SQLServer]Cannot find the object "post" because it does not exist or you do not have permissions." instead.Take a look at the particulars, and see if you can help me out.
The Code
Right now I have an Application.cfc, and two persistent CFCs, User.cfc, and Post.cfc, which look like the following:
Application.cfc
<cfscript>
this.ormenabled = true;
this.datasource = "test";
this.ormsettings.cfclocation = "objects";
this.ormsettings.dialect = "MicrosoftSQLServer";
this.ormsettings.dbcreate = "dropcreate";
this.ormSettings.logSQL = true;
this.developmentServer = true;
if ( this.developmentServer ) {
this.ormsettings.dbcreate = "dropcreate";
this.ormsettings.logSQL = true;
}
</cfscript>
<cffunction name="onRequestStart" access="public" hint="Request start processing" returnType="boolean" output="false">
<cfargument name="targetPage" type="string" hint="The page requested" required="true"/>
<cfif StructKeyExists(URL, "reload")>
<cfset ApplicationStop() />
<cflocation url="#arguments.targetPage#">
<cfreturn false />
</cfif>
<cfif IsDefined("url.logout")>
<cflogout />
</cfif>
<cflogin>
<cfif IsDefined("cflogin")>
<cfset user = EntityLoad("User", {
email = cflogin.name,
password = Hash(cflogin.password)
}, true) />
<cfif NOT IsNull(user)>
<cfloginuser name="#cflogin.name#" password="#cflogin.password#" roles="admin" />
</cfif>
</cfif>
</cflogin>
<cfreturn true />
</cffunction>
</cfcomponent>
User.cfc
<cfproperty name="userID" hint="The id for the user" type="numeric" fieldtype="id" datatype="integer" generator="identity" />
<cfproperty name="email" hint="Email address of the user" type="string" length="150" />
<cfproperty name="password" hint="Hash of the user's password" type="string" length="255" />
<!--- Relationships --->
<cfproperty name="poast" type="array" fieldtype="one-to-many" cfc="Post" fkcolumn="userID">
</cfcomponent>
Post.cfc
<cfproperty name="postID" type="numeric" fieldtype="id" datatype="integer" generator="identity" />
<cfproperty name="content" type="text" />
<cfproperty name="userID" type="numeric" length="255" />
<cfproperty name="dateCreated" type="date" />
<!--- Relationships --->
<cfproperty name="user" fieldtype="many-to-one" fkcolumn="userID" cfc="User" />
</cfcomponent>
The Error(s)
So the system should drop and create new tables if the specification is off, and I've tried to define a relationship between posts and users (yes, this is a bit of blog code). The two errors I get are:Error 1
Error 2
And whats weird is they just seem to alternate (not really random, just alternating). I'm assuming that its something to do with the relationship I defined (worked fine before that), but I'm not really seeing whats wrong. Any one know what to do?
Comments
this.ormsettings.dbcreate = "dropcreate";
command every request? Maybe try commenting it out and see if your error stops.
<cfproperty name="poast" type="array" fieldtype="one-to-many" cfc="Post" fkcolumn="userID">
Is that a typo in the name attribute?
@Henry: See, I thought about both of those things as well. I tried just refreshing a few times, but I just keep getting the same two messages alternating back and forth. I also tried clearing out the tables in the database, but that didn't seem to help anything.
@Bash: Yeah, you're right that is a typo. It was actually in the code I was running as well, but correcting it to "post" didn't change there resulting error message.