Sha256: 1903085c25972db14360ca5539e6ef9fa18ed3b012fd6a594eaa1ee9f5511ac9
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
module Unread module Reader module Scopes 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.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") end def have_read(readable) join_read_marks(readable).where('read_marks.id IS NOT NULL') end def with_read_marks_for(readable) join_read_marks(readable).select("#{quoted_table_name}.*, read_marks.id AS read_mark_id, '#{readable.class.base_class.name}' AS read_mark_readable_type, #{readable.id} AS read_mark_readable_id") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unread-0.6.1 | lib/unread/reader_scopes.rb |
unread-0.6.0 | lib/unread/reader_scopes.rb |