notification eagerly load the target
This commit is contained in:
parent
5ac194911f
commit
21bccedf9b
2 changed files with 3 additions and 2 deletions
|
|
@ -18,7 +18,8 @@ class NotificationsController < ApplicationController
|
|||
end
|
||||
|
||||
def index
|
||||
@notifications = Notification.for(current_user).include(:target).paginate :page => params[:page], :per_page => 25
|
||||
@notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id},
|
||||
:order => 'created_at desc', :include => [:target]).paginate :page => params[:page], :per_page => 25
|
||||
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
|
||||
respond_with @notifications
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Notification < ActiveRecord::Base
|
|||
belongs_to :target, :polymorphic => true
|
||||
|
||||
def self.for(recipient, opts={})
|
||||
self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc').include(:target)
|
||||
self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc')
|
||||
end
|
||||
|
||||
def self.notify(recipient, target, actor)
|
||||
|
|
|
|||
Loading…
Reference in a new issue