]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/note.rb
Merge remote-tracking branch 'upstream/master' into routing
[rails.git] / app / models / note.rb
index 67222191dbe7b84af69d1da81e9b7b4af7aff706..27357e58a86830620d6f5224f9a32a7ab7c000ae 100644 (file)
@@ -1,10 +1,7 @@
 class Note < ActiveRecord::Base
   include GeoRecord
 
-  has_many :comments, :class_name => "NoteComment",
-                      :foreign_key => :note_id,
-                      :order => :created_at,
-                      :conditions => { :visible => true }
+  has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
 
   validates_presence_of :id, :on => :update
   validates_uniqueness_of :id
@@ -14,6 +11,9 @@ class Note < ActiveRecord::Base
   validates_inclusion_of :status, :in => ["open", "closed", "hidden"]
   validate :validate_position
 
+  scope :visible, -> { where("status != 'hidden'") }
+  scope :invisible, -> { where("status = 'hidden'") }
+
   after_initialize :set_defaults
 
   # Sanity check the latitude and longitude and add an error if it's broken