No commit activity in last 3 years
No release in over 3 years
Optimize queries of ActiveRecord preload functions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 10.0
~> 1.3.6

Runtime

>= 4.2, < 5.3
 Project Readme

ActiveRecordAssociationQueryEconomizer

Enables to define preloading conditions in the arguments of has_one / has_many.

Condition is defined as an array of symbolized method name or Proc object.

Installation

Add this line to your application's Gemfile:

gem 'active_record_association_query_economizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_record_association_query_economizer

Usage

class SampleObject < ActiveRecord::Base
  has_many :sample_associations, preload_if: [:one_condition?, :another_condition?]

  def one_condition?
    true
  end

  def another_condition?
    false
  end
end

(Proc)

class SampleObject < ActiveRecord::Base
  has_many :sample_associations, preload_if: -> (record) {
    true
  }
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/negito6/active_record_association_query_economizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Development

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

Install develop version

cd /path/to/dir
git clone git@github.com/negito6/active_record_association_query_economizer.git
cd active_record_association_query_economizer
rake build
gem install pkg/active_record_association_query_economizer-X.Y.Z.gem

Testing

$ rake test:all

Run test for ActiveRecord version X.Y.Z

$ rake test:activerecord-X.Y.Z

License

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