Skip to main content
February 19, 2012
Question

CF10 ORM, MS SQL 2008 Express, id key not generating on PK

  • February 19, 2012
  • 1 reply
  • 1364 views

I am trying to get ORM running with CF10 and I'll admit this is my first attempt at using ORM.  I have been over several blog posts and lots of documentation but I keep hitting the same error over and over.  I am just trying to get the most simplistic setup running and I'm failing miserably.

Coldfusion 10 Zeus Beta w/ built-in web server

MS SQL 2008 Express

Error:

ids for this class must be manually assigned before calling save(): poster

I have tried several different iterations of poster.cfc with all kinds of generator settings and anything else I could find.  I will say it is creating the table in the database correct so at least it's getting that far.  Thank you in advance for your help, here is my code!

Application.cfc

component output="false" {

    this.name = "ROAR-CF10_" & hash( getCurrentTemplatePath() );

    this.ormEnabled = true;

    this.ormSettings.datasource = "roar";

    this.ormSettings.cfclocation = "/cfc";

    this.ormSettings.logsql = true;

    this.ormSettings.saveMapping = false;

    this.ormSettings.dbCreate = "dropcreate";

    function onRequestStart() {

          if ( structKeyExists(url,"init") )     ORMReload();

    }

    function onApplicationStart() {

        application.sitehome = "http://127.0.0.1:8500/roar/";

        application.assetURL = application.sitehome & "assets/";

        application.devmode = true;

    }

}

poster.cfc

** I've tried a ton of different combinations on the posterid line but nothing seems to do the trick for me.

component persistent="true" table="poster" {

    property name="posterid" fieldtype="id" generator="increment";

    property name="name" ormtype="string";

    property name="creationdate" ormtype="timestamp";

}

poster.cfm

<cfsilent><cfscript>

    if ( StructKeyExists(form,"posterBtn") ) {

        ePoster = EntityNew("poster");

        ePoster.setName(form.name);

        ePoster.setCreationdate(CreateODBCDateTime(now()));

        //ePoster = new cfc.Poster( {name:form.name,creationdate:CreateODBCDateTime(now())} );

        EntitySave(ePoster);

    }

</cfscript></cfsilent>

<cfoutput>

<!DOCTYPE html>

    <head>

        <title>ROAR - CF10 ORM Test</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link href="#application.assetURL#/css/bootstrap.css" rel="stylesheet" />

        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

        <script type="text/javascript" src="#application.assetURL#/js/bootstrap.js"></script>

    </head>

    <body>

        <div class="container-fluid">

            <div class="row-fluid">

                <div class="span2">

                    <h1>ROAR</h1>

                </div>

                <div class="span10">

                    <form method="post" class="well">

                        <h2>Create Poster</h2>

                        <label>Your Name: </label>

                        <input type="text" name="name" class="input-large" value="">

                        <div class="form-actions">

                            <button type="submit" class="btn btn-primary" name="posterBtn">Create User</button>

                        </div>

                    </form>

                </div>

            </div>

        </div>

    </body>

</html>

</cfoutput>

This topic has been closed for replies.

1 reply

February 19, 2012

So I figured out my problem on this one....

When I intially set everything up I had this.ormSettings.saveMapping = true.  At some point I realized that I didn't want that while I was testing so I set the value back to false.  Well, I didn't delete the generated file and apparently it was still using the file.  As soon as I deleted the file everything began to work as expected.