Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created January 27, 2013 16:25
Show Gist options
  • Select an option

  • Save jonleighton/4649087 to your computer and use it in GitHub Desktop.

Select an option

Save jonleighton/4649087 to your computer and use it in GitHub Desktop.
require "active_record"
require "logger"
puts ActiveRecord::VERSION::STRING
$rails4 = ActiveRecord::VERSION::MAJOR > 3
# ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
create_table :projects
create_table :tasks
end
class Project < ActiveRecord::Base
if $rails4
has_many :tasks, -> { where foo: 'a' }
else
has_many :tasks, conditions: { foo: 'a' }
end
end
class Task < ActiveRecord::Base
default_scope -> { where foo: 'b' }
end
p = Project.create
puts p.tasks.to_sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment