organic pagination support for followers/likes

#69 · closed · 3 comments

View on GitHub ↗

ajays1991

Hi, I was looking for organic pagination support for followers/likes for any object. `followers = current_user.followers(User)` returns array of collection where i don't want to pagination on the rails layer. I would prefer to have a organic pagination support for this on db layer something like this `current_user.followers(User).offset(0).limit(10)` i have not dig deep on the source code but something the following will also do fine. `current_user.followers(User, {offset: 0, limit: 10})`

Comments

ajays1991

https://github.com/cmer/socialization/pull/70

ExistsAndIs1

``` has_many :follows, foreign_key: :follower_id has_many :followees, foreign_key: :followable_id, class_name: "Follow" def user_followers User.joins(:follows).where(follows:{ followable_type: 'User', followable_id: self.id }) end def user_followees User.joins(:followees).where(follows:{ follower_type: 'User', follower_id: self.id }) end ``` Add this to your model as temporary fix or Monkey Patch ``` def followers(klass) klass.joins(:follows).where(follows:{ followable_type: klass.to_s, followable_id: self.id }) end ```

ajays1991

thanks