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

aston · 2013年08月13日 · 最后由 aston 回复于 2013年08月13日 · 2173 次阅读

例如 有一个模型 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 了,直接单独查询一下就好了

所言极是

需要 登录 后方可回复, 如果你还没有账号请 注册新账号