GroupedLatest
GroupedLatest is just another scope to get the latest record from each group.
Requirement
- Rails 4.2
Installation
# Gemfile
gem 'grouped_latest'
Usage
# app/models/post.rb
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :category
include GroupedLatest
end
$ rails c
> User.first.post.grouped_latest(:category_id)
Configuration
Post.latest_column = :id
Post.latest_strategy = :gl_arel_in
Strategies
WIP. I'm looking for the fastest logic.
$ rake test BENCH=1
Strategy Average
gl_arel_in 0.13105687065399252ms
gl_arel_exists 0.13757433084538206ms
gl_array_in 11.309650258132024ms
Licence
This project rocks and uses MIT-LICENSE.