0

私は2つの関係を持つモデルを持っています。

model.rb

has_many :items
has_many :top_items, :class_name => "Item", :limit => 3

したがって、インデックスのようなページでjsonをレンダリングする場合、top_itemsのみを取得したいと思います。しかし、Rablはこれを知らないようです。3ではなく、持っているすべてのアイテムが飛び出します。以下は私のrablコードです

child :top_items do |top_item|
    attributes :id, :name
end

何か案は?

4

1 に答える 1

0
If you eager load an association with a specified :limit option, it will be 
ignored, returning all the associated objects

したがって、has_many アソシエーションから子のサイズを制限することはできません。

于 2013-03-01T02:44:31.070 に答える