2012-08-03 29 views
2

好的,所以現在我真的很困惑,因爲我有這個工作一段時間後,一些已經改變,這導致我的計算屬性不起作用。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。

+0

任何人在那裏? :) – 2012-08-04 16:07:31

+0

如果只刪除linkUpVoteCount,那麼列linkDownVoteCount會發生同樣的錯誤嗎? – 2012-08-09 11:15:18

回答

2

聽起來像這樣是一個輪子的錯誤。我建議提交一個問題。

+0

嗨克里斯,是的,我在GitHub上爲CFWheels放置了一個'問題'...是正確的區域嗎?所以總的來說,我認爲在findAll()函數中與SELECT子句一起使用時計算的屬性是borked。通過borked我的意思是...破碎:) – 2012-08-09 16:03:48

+0

是的,在所有方面都是正確的。 – 2012-08-09 17:32:59

+0

克里斯爲你確認了這個錯誤以及儘管如此,車輪非常棒,我感謝你們的所有工作和努力。謝謝。 – 2012-08-09 22:54:05

-1

我不知道ColdFusion的,但也許你可以別名設置爲您的COUNT(*),像這樣:

<cfset property(name="linkUpVoteCount", sql="(SELECT COUNT(*) as linkUpVoteCount FROM votes WHERE votes.linkID = links.linkID AND voteType = 1)") /> 
+0

我的意思是,由於您收到的錯誤消息是「字段列表」中的「未知列'linkUpVoteCount'」,也許CFWheels試圖在您的SQL查詢中查找linkUpVoteCount列。 – 2012-08-09 13:54:47

+0

Wheels獲取'sql'參數中的內容,並在末尾添加'AS propertyName'。所以你最終會得到兩個'AS'es。 – 2012-08-09 15:26:26

+0

你收到了哪條錯誤消息?或者你從未嘗試過我所建議的? – 2012-08-09 15:53:03

-1

我不熟悉你的框架,但試試這個:

<cfset property(name="linkUpVoteCount", sql="(SELECT COUNT(*) FROM votes WHERE votes.linkID = links.linkID AND voteType = 1) as linkUpVoteCount") /> 

在sql子查詢外部放置as linkUpVoteCount別名。

此外,我敢肯定你不需要<cfset>'s末尾的所有/>斜線。 html5 ftw。

+0

Wheels取出sql參數中的內容並將AS propertyName添加到最後。所以你最終會得到兩個ASes。 – 2012-08-09 15:26:42

+0

那永遠不會工作... – 2012-08-09 15:30:32

+0

感謝您的嘗試,但這不起作用。 – 2012-08-09 16:02:22