简体   繁体   English

什么是查询此信息的有效方法? [RoR]

[英]What is a efficient way to query for this information? [RoR]

Okay basically I'm trying to query the community_posts model and count the amount of posts where .community_topic_id is equal to community_topic which is a param. 好的,基本上我正在尝试查询community_posts模型并计算.community_topic_id等于community_topic这是一个参数的帖子数量。 I was looking over the doc and I have a few ideas of how to do but, I want to make sure I'm doing it right as I have a few similar queries I'm writing for various other methods. 我正在查看文档,但对如何操作有一些想法,但是我想确保自己做得对,因为我正在为其他各种方法编写一些类似的查询。

Hope this isn't too broad.. Not trying to ignite a "opinion war" I just want a way to do that wont turn out to be inefficient and force me to change my other queries. 希望这不会太广泛。.不要试图引发一场“意见战争”,我只是想要一种方法,但结果却效率低下,不会迫使我改变其他问题。

Appreciate your help. 感谢您的帮助。

def topicreplycount(community_topic)
    "Code for query"
end
CommunityPost.count(community_topic_id: community_topic)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM