0
0
Fork 0

Pre-loading polymorphic associations for Atom feeds

This commit is contained in:
Eugen Rochko 2016-03-24 13:21:53 +01:00
parent 7e58303a8d
commit 0f5bbb999c
4 changed files with 22 additions and 6 deletions

View file

@ -1,11 +1,12 @@
class StreamEntry < ActiveRecord::Base
include Paginable
belongs_to :account, inverse_of: :stream_entries
belongs_to :activity, polymorphic: true
validates :account, :activity, presence: true
scope :with_includes, -> { includes(:activity) }
scope :paginate_by_max_id, -> (limit, max_id) { order('id desc').limit(limit).where(max_id.nil? ? '1=1' : ['id < ?', max_id]) }
scope :with_includes, -> { includes(:activity) }
def object_type
orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)