好的,所以現在我真的很困惑,因爲我有這個工作一段時間後,一些已經改變,這導致我的計算屬性不起作用。CFWheels - 計算屬性在查詢中產生列錯誤
我有一個「頁面」控制器在「鏈接」模型上執行findAll()。這很好,除了當我嘗試包括一個計算的屬性(曾經工作)。
page.cfc(控制器)
<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(模型)
<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(視圖)
#linkListHottest.linkUpVoteCount#
我得到以下錯誤:
Unknown column 'linkUpVoteCount' in 'field list'
好吧,我想,我們刪除從SELECT中的findAll(列名),看看是否能解決它。不要:
column [LINKUPVOTECOUNT] not found in query, columns are [linkID,linkTitle,linkPoints,linkAuthority,linkCreated,userID,userName,categoryID,categoryTitle,categoryToken]
所以它看起來像一個catch 22的情況。這就好像我的「鏈接」模型忽略了完全設置的屬性。
我會很感激任何反饋,我要去哪裏錯了(我確定這是我!)。
非常感謝, Michael。
任何人在那裏? :) – 2012-08-04 16:07:31
如果只刪除linkUpVoteCount,那麼列linkDownVoteCount會發生同樣的錯誤嗎? – 2012-08-09 11:15:18