「モデル」オブジェクトを表示するときに、参照される「モノ」ドキュメントの数を制限する必要がある REST API ルートがあります。
主なモデル:
class Model
include Mongoid::Document
has_many :things
end
参照モデル:
class Thing
include Mongoid::Document
belongs_to :model
end
モデルコントローラー:
def show
# this should retrieve the first 30 "Things" that belong to the model we found
@model = Model.find(params[:id])
# I attempted this with no luck:
# @model = Model.find(params[:id]).includes(:things).limit(30)
end
モデルの一部である最初の N 個の参照レコードを取得するにはどうすればよいですか?