sqlcoldfusionrailocfwheels

CFWheels - Calculated property generates column error in query


Ok, so this is really confusing me now, because I had this working a while back and something has changed which has caused my calculated properties to not work.

I have a "page" controller that does a findAll() on the "link" model. This works great, except for when I try to include a calculated property (which used to work).

page.cfc (controller)

<cfset linkListHottest = model("link").findAll(

            select="

                links.linkID,
                linkTitle,
                linkPoints,
                linkAuthority,
                linkCreated,
<!--- Here I specifiy the 'property' names from the model --->
                linkUpVoteCount,
                linkDownVoteCount,
                linkCommentCount,

                users.userID,
                userName,

                categories.categoryID,
                categoryTitle,
                categoryToken",

            include="user,category", 
            order="linkPoints DESC",
            handle="linkListHottestPaging",

            page=params.page,
            perPage=5

        ) />

link.cfc (model)

<cffunction name="init">

        <cfset table("links") />

<!--- These three lines aren't populating my queries on the link model --->
        <cfset property(name="linkUpVoteCount", sql="(SELECT COUNT(*) FROM votes WHERE votes.linkID = links.linkID AND voteType = 1)") />
        <cfset property(name="linkDownVoteCount", sql="(SELECT COUNT(*) FROM votes WHERE votes.linkID = links.linkID AND voteType = 0)") />
        <cfset property(name="linkCommentCount", sql="(SELECT COUNT(*) FROM comments WHERE comments.linkID = links.linkID AND commentRemoved = 0)") />

        <cfset belongsTo(name="user", modelName="user", joinType="outer", foreignKey="userID") />
        <cfset belongsTo(name="category", modelName="category", joinType="outer", foreignKey="categoryID") />

        <cfset hasMany(name="vote", modelName="vote", joinType="outer", foreignKey="linkID") />
        <cfset hasMany(name="comment", modelName="comment", joinType="outer", foreignKey="linkID") />   

        <cfset validatesPresenceOf(property='linkTitle') />
        <cfset validatesPresenceOf(property='linkURL') />
        <cfset validate(property='linkURL', method='isValidURL') />
        <cfset validate(property='linkURL', method="validateUniqueUrl", when="onCreate") />

    </cffunction>

home.cfm (view)

#linkListHottest.linkUpVoteCount#

I get the following error:

Unknown column 'linkUpVoteCount' in 'field list'

Ok, I thought, let's remove the column names from the SELECT in the findAll() and see if that solves it. Nope:

column [LINKUPVOTECOUNT] not found in query, columns are [linkID,linkTitle,linkPoints,linkAuthority,linkCreated,userID,userName,categoryID,categoryTitle,categoryToken]

So it seems like a catch 22 situation. It's almost as if my "link" model is ignoring the properties set there entirely.

I would appreciate any feedback on where I'm going wrong (I'm sure it's me!).

Many thanks, Michael.


Solution

  • Sounds like this is a bug with Wheels. I suggest filing an issue.