diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 59695bd04..d7cd7dcd1 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -17,7 +17,7 @@ class Dmail < ActiveRecord::Base scope :deleted, where(["is_deleted = ?", true]) scope :search_message, lambda {|query| where(["message_index @@ plainto_tsquery(?)", query])} scope :unread, where("is_read = false and is_deleted = false") - scope :visible, lambda {where("(to_id = ? or from_id = ?)", CurrentUser.id, CurrentUser.id)} + scope :visible, lambda {where("owner_id = ?", CurrentUser.id)} scope :to_name_matches, lambda {|name| where("to_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} scope :from_name_matches, lambda {|name| where("from_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} search_method :to_name_matches, :from_name_matches