0

我有一个基本查询来获取我的数据库表“帖子”中的所有“帖子”。登录的用户可以对这些帖子发表评论。但是,我希望能够突出显示(在查看所有帖子时)用户之前评论过哪些帖子。

我目前的查询如下所示:

<cfset posts = model("post").findAll(

            select = "

                posts.postID,
                postTitle,
                postPoints,
                postAuthority,
                postCreated,
                postDescription,

                postCommentCount,
                postUpVoteCount,
                postDownVoteCount,

                users.userID,
                userName,

                categories.categoryID,
                categoryTitle,
                categoryToken",

            include     = "user,category", 
            order       = "postPoints DESC",
            page        = params.page,
            perPage     = params.pageQuantity

        ) />

我得到所有帖子并加入创建帖子的用户以及类别信息等。

我该如何修改它,以便如果用户登录,他们将能够看到他们已经评论过哪些帖子?用户发表的评论数量并不重要,只要用户发表了评论就行。

我不想在每个帖子上运行查询来检查这一点。理想情况下,最好将此查询加入计数。

除此之外,我在帖子模型中有 3 个查询:

 <cfset property(name="postUpVoteCount", sql="SELECT COUNT(*) FROM votes WHERE votes.postID = posts.postID AND votes.voteType = 1") />
        <cfset property(name="postDownVoteCount", sql="SELECT COUNT(*) FROM votes WHERE votes.postID = posts.postID AND votes.voteType = 0") />
        <cfset property(name="postCommentCount", sql="SELECT COUNT(*) FROM comments WHERE comments.postID = posts.postID AND comments.commentRemoved = 0") />

我可以在查询中使用它吗?

有任何想法吗?

谢谢,米奇。

4

0 回答 0