Low commit activity in last 3 years
A long-lived project that still receives updates
ActiveRecordDistinctOn adds support for `DISTINCT ON` to ActiveRecord. At the time of this writing, PostgreSQL is the only database which supports this syntax; however, this gem has been written with database independence in mind so that if another Arel visitor adds support for `Arel::Nodes::DistinctOn` in the future, it should work seamlessly.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 12.3.3
>= 0
>= 0

Runtime

>= 6.1, < 7.3
 Project Readme

ActiveRecordDistinctOn

Gem Version Build Status Code Climate Test Coverage Security

ActiveRecordDistinctOn adds support for DISTINCT ON queries to ActiveRecord. At the time of this writing, PostgreSQL is the only database which supports this syntax; however, this gem has been written with database independence in mind so that if another Arel visitor adds support for Arel::Nodes::DistinctOn in the future, it should work seamlessly.

Installation

Add this line to your application's Gemfile:

gem 'active_record_distinct_on'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_record_distinct_on

Usage

This gem defines ActiveRecord::Base.distinct_on and ActiveRecord::Relation#distinct_on. Both accept a variable number of column arguments.

For example:

Dog.distinct_on(:name, :owner_id)

Generates SQL like:

SELECT DISTINCT ON ( "dogs"."name", "dogs.owner_id" ) "dogs".* FROM "dogs"

Note: For applications using ActiveRecord à la carte (without the rails gem), none of the methods above will be defined until ActiveRecordDistinctOn.install is manually called.

Development

The development dependencies of this gem are managed using Bundler.

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake test:all to run the tests. You can also run bundle exec rake console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to RubyGems.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.