- has_many :comments, :class_name => "NoteComment",
- :foreign_key => :note_id,
- :order => :created_at,
- :conditions => { :visible => true }
-
- validates_presence_of :id, :on => :update
- validates_uniqueness_of :id
- validates_numericality_of :latitude, :only_integer => true
- validates_numericality_of :longitude, :only_integer => true
- validates_presence_of :closed_at if :status == "closed"
- validates_inclusion_of :status, :in => ["open", "closed", "hidden"]
+ has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
+ has_many :all_comments, -> { left_joins(:author).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id, :inverse_of => :note
+
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :only_integer => true }
+ validates :latitude, :longitude, :numericality => { :only_integer => true }
+ validates :closed_at, :presence => true, :if => proc { :status == "closed" }
+ validates :status, :inclusion => %w[open closed hidden]
+