Skip to content

Instantly share code, notes, and snippets.

@syrm
Created January 14, 2013 20:22
Show Gist options
  • Save syrm/4533039 to your computer and use it in GitHub Desktop.
Save syrm/4533039 to your computer and use it in GitHub Desktop.
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