Created
January 14, 2013 20:22
-
-
Save syrm/4533039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
include ActiveModel::ForbiddenAttributesProtection | |
has_secure_password | |
has_many :topics, foreign_key: 'author_id' | |
def unread_topics | |
Topic | |
.select('topics.*') | |
.joins('LEFT JOIN read_marks ON read_marks.topic_id = topics.id AND read_marks.user_id = %d' % [ id ]) | |
.where('read_marks.id IS NULL OR read_marks.reply_id IS NULL OR read_marks.reply_id < topics.last_reply_id') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment