我以下列方式发回一个json对象:
respond_with @authors, include: :posts
我需要限制posts
的数量。我尝试过:
respond_with @authors, include: :posts, limit: 10
但它不起作用。
答案 0 :(得分:2)
我在这里做的是为latest_posts
创建一个关系:
class Author
has_many :latest_posts, -> { limit(10) }, class_name: Post
end
# usage
respond_with @authors, include: :latest_posts