Adds column based query chains to ActiveRecord
Add this line to your application's Gemfile:
gem 'active_record-column_where_chain'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_record-column_where_chain
ActiveRecord::ColumnQueryChain exposes Arel Predicates to the Active Record query api.
MyModel.where(:my_column).matches("%SomeValue%") #=> SELECT * from my_models where my_column like '%SomeValue'
MyModel.where(:my_column).gt(10) #=> SELECT * from my_models where my_column > 10
Or you can define your own predicates.
class MyModel < ActiveRecord::Base
predicate :starts_with do |column, value|
column.matches("#{value}%")
end
end
MyModel.where(:my_column).starts_with("Bar")
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request