diff options
| author | Kir | 2011-11-01 20:23:57 +0400 |
|---|---|---|
| committer | Kir | 2011-11-01 20:23:57 +0400 |
| commit | e855fb8574570934cde28cfb190cc3cba31fbec0 (patch) | |
| tree | 8cd131551d43b3aaa13d7d7e71517b1424271ff0 /app/models | |
| parent | 6477ad7cdba8a06fa00be6c374aaa1cad2d2f505 (diff) | |
| download | inboxes-e855fb8574570934cde28cfb190cc3cba31fbec0.tar.bz2 | |
New scope and templates
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/discussion.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb index cc1da7a..ad53523 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -13,10 +13,12 @@ class Discussion < ActiveRecord::Base has_many :users, :through => :speakers # отметки о прочтении юзеров - # has_many :views, :dependent => :destroy, :class_name => "DiscussionView" - - # жутко неоптимизированная часть, возможны баги - # scope :unread_for, lambda { |user_or_user_id| joins(:views, :speakers).where("discussions.updated_at >= discussion_views.updated_at AND speakers.user_id = ?", user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id ) } + has_many :views, :dependent => :destroy, :class_name => "DiscussionView" + + scope :unread_for, (lambda do |user_or_user_id| + user = user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id + joins(:views, :speakers).where("discussions.updated_at >= discussion_views.updated_at AND speakers.user_id = ? AND discussion_views.user_id = ?", user, user) + end) accepts_nested_attributes_for :messages @@ -81,9 +83,9 @@ class Discussion < ActiveRecord::Base end # дата последнего сообщения в дискуссии - def last_message_at - self.messages.last ? self.messages.last.created_at : nil - end + # def last_message_at + # self.messages.last ? self.messages.last.created_at : nil + # end # проверка, является ли дискуссия непрочитанной для пользователя def unread_for?(user) |
