Class: EvilQuery::Participation

Inherits:
Base
  • Object
show all
Defined in:
lib/evil_query.rb

Instance Method Summary collapse

Methods inherited from Base

#fetch_ids!, #id_sql

Constructor Details

#initialize(user) ⇒ Participation

Returns a new instance of Participation.


18
19
20
21
# File 'lib/evil_query.rb', line 18

def initialize(user)
  @user = user
  @class = Post
end

Instance Method Details

#postsObject


23
24
25
26
27
28
29
30
# File 'lib/evil_query.rb', line 23

def posts
  author_id = @user.person_id
  Post.joins("LEFT OUTER JOIN participations ON participations.target_id = posts.id AND " \
             "participations.target_type = 'Post'")
      .where(::Participation.arel_table[:author_id].eq(author_id).or(Post.arel_table[:author_id].eq(author_id)))
      .order("posts.interacted_at DESC")
      .distinct
end