diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
commit | 2d1866d966d94c688f9cb87c5bf3f096dffac844 (patch) | |
tree | 7a733c1cc51448ab69b3f892285305dbfb0ae15e /app/models/news.rb | |
parent | a6ec78a4dc658e3517ed682792016b6530458696 (diff) | |
download | redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.tar.gz redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.zip |
Merged rails-4.1 branch (#14534).
git-svn-id: http://svn.redmine.org/redmine/trunk@13482 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/news.rb')
-rw-r--r-- | app/models/news.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/models/news.rb b/app/models/news.rb index b86e3f63d..baaa92fba 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -19,16 +19,18 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" + has_many :comments, lambda {order("created_on")}, :as => :commented, :dependent => :delete_all validates_presence_of :title, :description validates_length_of :title, :maximum => 60 validates_length_of :summary, :maximum => 255 + attr_protected :id acts_as_attachable :delete_permission => :manage_news - acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project + acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], + :scope => preload(:project) acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} - acts_as_activity_provider :find_options => {:include => [:project, :author]}, + acts_as_activity_provider :scope => preload(:project, :author), :author_key => :author_id acts_as_watchable @@ -36,7 +38,9 @@ class News < ActiveRecord::Base after_create :send_notification scope :visible, lambda {|*args| - includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) + joins(:project). + references([:author, :project]). + where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) } safe_attributes 'title', 'summary', 'description' @@ -68,7 +72,7 @@ class News < ActiveRecord::Base # returns latest news for projects visible by user def self.latest(user = User.current, count = 5) - visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all + visible(user).joins([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).to_a end private |