Rails eager load 时,怎么限定 includes 载入对象的数量

aston · August 13, 2013 · Last by aston replied at August 13, 2013 · 2174 hits

例如 有一个模型 Post,has_many :comments Post.includes(:comments) comments 会全部载入

rails 文档里这样说, If you eager load an association with a specified :limit option, it will be ignored, returning all the associated objects:

如想 limit 怎么办,大家遇到过这样的问题吗?有什么好的解决方法?

一对多的东西就没必要 includes 了,直接单独查询一下就好了

所言极是

You need to Sign in before reply, if you don't have an account, please Sign up first.