0
我已經款設立與此類似:的Rails 3 - 斯科普斯
class Book < ActiveRecord::Base
has_many :histories, as: :object
end
class Magazine < ActiveRecord::Base
has_many :histories, as: :object
end
class Action < ActiveRecord::Base
belongs_to :object, polymorphic: true
default_scope order(:done_at)
# a history contains an action and the time that action
# occurred on the object it belongs to
end
現在,我想對所有對象發生的5個最新的操作的列表。所以,我可以這樣做:
Action.limit(5)
然而,問題是,如果兩個行動近日對同一本書發生後,兩個動作將被檢索。我只想檢索最新的一個。我如何實現這一目標?