0
我通過以下方式發送回一個JSON對象:如何限制響應中關聯中包含的記錄數?
respond_with @authors, include: :posts
我需要限制的posts
數量。我試過:
respond_with @authors, include: :posts, limit: 10
但它不工作。
我通過以下方式發送回一個JSON對象:如何限制響應中關聯中包含的記錄數?
respond_with @authors, include: :posts
我需要限制的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