lib/unread/reader_scopes.rb in unread-0.6.3 vs lib/unread/reader_scopes.rb in unread-0.7.0
- old
+ new
@@ -1,14 +1,21 @@
module Unread
module Reader
module Scopes
+ # This class method may be overriden to restrict readers to a subset of records
+ # It must return self or a ActiveRecord::Relation
+ def reader_scope
+ self
+ end
+
def join_read_marks(readable)
assert_readable(readable)
joins "LEFT JOIN read_marks
ON read_marks.readable_type = '#{readable.class.base_class.name}'
AND (read_marks.readable_id = #{readable.id} OR read_marks.readable_id IS NULL)
- AND read_marks.user_id = #{quoted_table_name}.#{quoted_primary_key}
+ AND read_marks.reader_id = #{quoted_table_name}.#{quoted_primary_key}
+ AND read_marks.reader_type = '#{connection.quote_string base_class.name}'
AND read_marks.timestamp >= '#{connection.quoted_date readable.send(readable.class.readable_options[:on])}'"
end
def have_not_read(readable)
join_read_marks(readable).where('read_marks.id IS NULL')
\ No newline at end of file