Note that there are some explanatory texts on larger screens.

plurals
  1. POCFWheels - Calculated property generates column error in query
    primarykey
    data
    text
    <p>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.</p> <p>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).</p> <p><strong>page.cfc (controller)</strong></p> <pre><code>&lt;cfset linkListHottest = model("link").findAll( select=" links.linkID, linkTitle, linkPoints, linkAuthority, linkCreated, &lt;!--- Here I specifiy the 'property' names from the model ---&gt; linkUpVoteCount, linkDownVoteCount, linkCommentCount, users.userID, userName, categories.categoryID, categoryTitle, categoryToken", include="user,category", order="linkPoints DESC", handle="linkListHottestPaging", page=params.page, perPage=5 ) /&gt; </code></pre> <p><strong>link.cfc (model)</strong></p> <pre><code>&lt;cffunction name="init"&gt; &lt;cfset table("links") /&gt; &lt;!--- These three lines aren't populating my queries on the link model ---&gt; &lt;cfset property(name="linkUpVoteCount", sql="(SELECT COUNT(*) FROM votes WHERE votes.linkID = links.linkID AND voteType = 1)") /&gt; &lt;cfset property(name="linkDownVoteCount", sql="(SELECT COUNT(*) FROM votes WHERE votes.linkID = links.linkID AND voteType = 0)") /&gt; &lt;cfset property(name="linkCommentCount", sql="(SELECT COUNT(*) FROM comments WHERE comments.linkID = links.linkID AND commentRemoved = 0)") /&gt; &lt;cfset belongsTo(name="user", modelName="user", joinType="outer", foreignKey="userID") /&gt; &lt;cfset belongsTo(name="category", modelName="category", joinType="outer", foreignKey="categoryID") /&gt; &lt;cfset hasMany(name="vote", modelName="vote", joinType="outer", foreignKey="linkID") /&gt; &lt;cfset hasMany(name="comment", modelName="comment", joinType="outer", foreignKey="linkID") /&gt; &lt;cfset validatesPresenceOf(property='linkTitle') /&gt; &lt;cfset validatesPresenceOf(property='linkURL') /&gt; &lt;cfset validate(property='linkURL', method='isValidURL') /&gt; &lt;cfset validate(property='linkURL', method="validateUniqueUrl", when="onCreate") /&gt; &lt;/cffunction&gt; </code></pre> <p><strong>home.cfm (view)</strong></p> <pre><code>#linkListHottest.linkUpVoteCount# </code></pre> <p>I get the following error:</p> <blockquote> <p>Unknown column 'linkUpVoteCount' in 'field list'</p> </blockquote> <p>Ok, I thought, let's remove the column names from the SELECT in the findAll() and see if that solves it. Nope:</p> <blockquote> <p>column [LINKUPVOTECOUNT] not found in query, columns are [linkID,linkTitle,linkPoints,linkAuthority,linkCreated,userID,userName,categoryID,categoryTitle,categoryToken]</p> </blockquote> <p>So it seems like a catch 22 situation. It's almost as if my "link" model is ignoring the properties set there entirely.</p> <p>I would appreciate any feedback on where I'm going wrong (I'm sure it's me!).</p> <p>Many thanks, Michael.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload