I am new to Cfwheels and MVC. Cfwheels website is up and running.
I have successfully completed https://guides.cfwheels.org/docs/beginner-tutorial-hello-world .
Now I am trying to just test the cfwheels to mySql database connection. I have NO tables in the mySql database.
The error I get is;
Wheels.TableNotFound ttt_shows table could not be found in the database.
Suggested action
Add a table named ttt_shows to your database or tell CFWheels to use a different table for this model. For example you can tell a user model to use a table called tbl_users by creating a User.cfc file in the models folder, creating an init method inside it and then calling table("tbl_users") from within it.
The ttt_shows table could not be found in the database. < Error location: Line 4 in views\ttt_show\cf_info_mysql.cfm ;
<cfset mySqlVerStruct= model("ttt_show").getMySqlVersion1() />Tag context;
Error thrown on line 169 in wheels\model\adapters\Base.cfc
called from line 72 in wheels\model\initialization.cfm
called from line 1 in root.cfm
called from line 576 in wheels\global\internal.cfm
called from line 861 in wheels\global\internal.cfm
called from line 164 in wheels\global\cfml.cfm
called from line 14 in wheels\global\cfml.cfm
called from line 206 in wheels\global\public.cfm
called from line 4 in views\ttt_show\cf_info_mysql.cfm
called from line 128 in wheels\global\cfml.cfm
called from line 434 in wheels\controller\rendering.cfm
called from line 157 in wheels\controller\rendering.cfm
called from line 53 in wheels\controller\rendering.cfm
called from line 141 in wheels\controller\processing.cfm
called from line 95 in wheels\controller\processing.cfm
called from line 198 in wheels\dispatch\request.cfm
called from line 1 in wheels\index.cfm
called from line 1 in index.cfm
called from line 1 in wheels\events\onrequest.cfm
Note: A related/subpart of my question is; In CfWheels, how do I create a model that does not have an associated database table? In the future I will need to code a model that does not have a database attached - but does CRUD operations against an xml or json file. Thanks in advance for any help / guidance.
So far I have the following code;
<!--- FILE: ..\views\ttt_show.cfm --->
<h1>MySql Version Query using; model("ttt_show").getMySqlVersion1() </h1>
<cfset mySqlVerStruct= model("ttt_show").getMySqlVersion1() />
<cfdump var="#mySqlVerStruct#" label="MySql version" />
<cfcomponent extends="Model">
<!--- FILE: ..\models\ttt_show.cfc --->
<cffunction name="init">
</cffunction>
<!--- - - getMySqlVersion1() - - --->
<cffunction name="getMySqlVersion1">
<!--- USED BY ..\views\ttt_show\cf_info_mysql.cfm --->
<cfset retStruct=S tructNew( "qryMySqlVersion1") />
<cfset retStruct.errorStr="" />
<cfset retStruct.datasource="#get('dataSourceName')#" />
<cfset retStruct.username="#get('dataSourceUserName')#" />
<cfset retStruct.password="#get('dataSourcePassword')#" />
<cfset retStruct.qry="" />
<cfreturn retStruct>
</cffunction>
<!--- - - getMySqlVersion2() - - --->
<cffunction name="getMySqlVersion2">
<!--- USED BY ..\views\ttt_show\cf_info_mysql.cfm --->
<cfquery name="MySqlVersion2" debug="no" datasource="#APPLICATION.wheels.DATASOURCENAME#" timeout="5">
select version() as mysql_version
</cfquery>
<cfreturn MySqlVersion2>
</cffunction>
<!--- - - Create...Table() - - --->
<cffunction name="createEmptyTable">
<cfquery result="myCreateTblResults" datasource="#get('dataSourceName')#">
CREATE TABLE IF NOT EXISTS `tbl_masters` ( `id` int(11) unsigned NOT NULL auto_increment COMMENT 'unique primary key id', `textValue` varchar(255) default NULL COMMENT 'any text value', `numValue` int(11) default NULL COMMENT 'any numeric value', `dtValue`
datetime default NULL COMMENT 'any datetime value', `recStatus` tinyint(4) NOT NULL default '1' COMMENT 'Status of This Record', `dtCreated` datetime NOT NULL COMMENT 'date that record was created', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8
COMMENT='Stores any general key/value pairs for app, MASTER in master-slaves relationship';
</cfquery>
<!--- return false: error: not tested yet --->
<cfreturn false>
</cffunction>
</cfcomponent>
<cfcomponent extends="Controller"><!--- FILE: ..\controllers\ttt_show.cfc --->
<!---
--- Show debug info / or test a '..\view\*.cfm file.
--->
<!--- SEE ..\views\ttt_show\cf_info_mysql.cfm --->
<cffunction name="cf_info_mysql">
</cffunction>
</cfcomponent>
After reading further, I found out the general answer (but have not tested code yet).
At https://guides.cfwheels.org/docs/object-relational-mapping under the heading; "Models Without Database Tables", documentation explains that in your model/*.cfm file, you need to add;
From the document;
Now if I can just find a source code example of this type of model.