Last active
August 14, 2025 09:09
-
-
Save Bodacious/bcad497032211e39d374116ed85d2d22 to your computer and use it in GitHub Desktop.
Expressing less-than and greater-than queries in active record with Ruby notation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'sqlite3' | |
gem 'activerecord', require: 'active_record' | |
end | |
# NOTE: uncomment to show logging | |
# ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.establish_connection({ | |
:adapter => 'sqlite3', | |
:database =>":memory:", | |
}) | |
ActiveRecord::Schema.define do | |
create_table :foobars, force: true do |t| | |
t.integer :foo | |
end | |
end | |
class Foobar < ActiveRecord::Base | |
end | |
puts Foobar.where(foo: ...100).to_sql | |
puts Foobar.where(foo: ..100).to_sql | |
puts Foobar.where.not(foo: ..100).to_sql | |
puts Foobar.where.not(foo: ...100).to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment