Skip to content

Commit

Permalink
Simplifies Followable#following_by_type.
Browse files Browse the repository at this point in the history
  • Loading branch information
james2m committed Sep 22, 2011
1 parent bbc4295 commit ed4822d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ def all_following(options={})

# Returns the actual records of a particular type which this record is following.
def following_by_type(followable_type, options={})
follows = followable_type.constantize.
followables = followable_type.constantize.
includes(:followings).
where('blocked = ?', false).
where(
"follows.follower_id = ? AND follows.follower_type = ? AND follows.followable_type = ?",
self.id, parent_class_name(self), followable_type
)
where('follows.blocked' => false,
'follows.follower_id' => self.id,
'follows.follower_type' => parent_class_name(self),
'follows.followable_type' => followable_type)
if options.has_key?(:limit)
follows = follows.limit(options[:limit])
followables = followables.limit(options[:limit])
end
follows
followables
end

def following_by_type_count(followable_type)
Expand Down

0 comments on commit ed4822d

Please sign in to comment.