Ruby on rails 如何限制响应中关联中包含的记录数?
我以以下方式发回一个json对象:Ruby on rails 如何限制响应中关联中包含的记录数?,ruby-on-rails,rails-activerecord,Ruby On Rails,Rails Activerecord,我以以下方式发回一个json对象: respond_with @authors, include: :posts 我需要限制帖子的数量。我试过: respond_with @authors, include: :posts, limit: 10 但是它不起作用。我在这里要做的是为最新发布创建一个关系: class Author has_many :latest_posts, -> { limit(10) }, class_name: Post end # usage respo
respond_with @authors, include: :posts
我需要限制帖子的数量
。我试过:
respond_with @authors, include: :posts, limit: 10
但是它不起作用。我在这里要做的是为
最新发布创建一个关系:
class Author
has_many :latest_posts, -> { limit(10) }, class_name: Post
end
# usage
respond_with @authors, include: :latest_posts