Created
November 18, 2013 23:22
-
-
Save jonleighton/7537203 to your computer and use it in GitHub Desktop.
A demonstration that "unscoped" just clobbers everything in the scope chain
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
-- create_table(:posts) | |
-> 0.0189s | |
-- create_table(:comments) | |
-> 0.0005s | |
4.0.1 | |
SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? ORDER BY comments.id desc | |
SELECT "comments".* FROM "comments" | |
SELECT "comments".* FROM "comments" |
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
gem "rails", "~> 4.0.0" | |
require "active_record" | |
require "logger" | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
# ActiveRecord::Base.logger = Logger.new(STDERR) | |
ActiveRecord::Schema.define do | |
create_table :posts | |
create_table :comments do |t| | |
t.integer :post_id | |
end | |
end | |
class Comment < ActiveRecord::Base | |
default_scope { order "comments.id desc" } | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
puts ActiveRecord::VERSION::STRING | |
post = Post.create | |
puts post.comments.to_sql | |
puts post.comments.unscoped.to_sql | |
puts Comment.order("omg").where("wtf").unscoped.to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment