I have an issue with CF9 ORM mapping.
I get the following error from time to time (yes, it works fine most of the time),
Mapping for component model.Pubs not found. Either the mapping for this component is missing or the application must be restarted to generate the mapping.
ORM definition in Application.cfc
<cfscript>
this.datasource = "Pubs";
this.ormenabled = true;
this.ormsettings= {
dialect="MicrosoftSQLServer",
dbcreate="update",
eventhandling="true"
};
</cfscript>
<cfset this.mappings["/model"] = getDirectoryFromPath(getCurrentTemplatePath()) & "model" />
The only way to fix it is to refresh the ORM couple of time, which is by hitting ?init=true on Application.cfc. It is still a temporary solution, but I need to know the root cause of it and fix it.
<cfscript>
if(structKeyExists(url, "init")) { ormReload(); applicationStop(); location('index.cfm?reloaded=true'); }
Please advise.
Thanks!
Okay, thank you both @Henry and @Walter for your comments. They were the lead toward the right solution.
Here's what I did to make sure it's stable ALL the time.
On the /root/Application.cfc, I adjusted the following code
<cfset application.mappings["/ormmodel"] = expandPath("/root/ormmodel") />
and
this.ormsettings= {
cfclocation = ["ormmodel"],
autogenmap = true,
...
eventhandling="true"
};
Notice the missing "/" in the cfclocation value.
On calling for model components, I changed the code from pub = new ormmodel.Pubs() to
pub = EntityNew("Pubs");
On an unrelated point, I've changed my components name to camelCase naming and avoided special characters like underscores and dashes.
I hope this would be helpful and save someone else hours of frustration and suspense.
Happy coding!