]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/note.rb
Merge branch 'master' into openstreetbugs
[rails.git] / app / models / note.rb
index 0512639e15c5ac4ebf75ff123517013991a7bd79..892ada1aa8a5163d474bbde166ca4b9251f4d1fa 100644 (file)
@@ -4,7 +4,7 @@ class Note < ActiveRecord::Base
   has_many :comments, :class_name => "NoteComment",
                       :foreign_key => :note_id,
                       :order => :created_at,
-                      :conditions => "visible = true AND body IS NOT NULL"
+                      :conditions => { :visible => true }
 
   validates_presence_of :id, :on => :update
   validates_uniqueness_of :id
@@ -72,4 +72,17 @@ class Note < ActiveRecord::Base
   def author_name
     self.comments.first.author_name
   end
+
+  # Custom JSON output routine for notes
+  def to_json(options = {})
+    super options.reverse_merge(
+      :methods => [ :lat, :lon ], 
+      :only => [ :id, :status, :created_at ],
+      :include => {
+         :comments => {
+           :only => [ :event, :author_name, :created_at, :body ]
+         }
+      }
+    )
+  end
 end