Created
October 12, 2012 18:14
-
-
Save miyucy/3880636 to your computer and use it in GitHub Desktop.
This file contains 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
class Post < ActiveRecord::Base | |
acts_as_paranoid | |
default_scope where :status => nil | |
end | |
# > Post | |
# => Post(id: integer, title: string, body: text, deleted_at: datetime, created_at: datetime, updated_at: datetime, status: string) | |
# > Post.all | |
# Post Load (0.2ms) SELECT "posts".* FROM "posts" WHERE "posts"."status" IS NULL AND ("posts"."deleted_at" IS NULL) | |
# => [] | |
# > scope = Post.scoped.with_default_scope | |
# Post Load (0.2ms) SELECT "posts".* FROM "posts" WHERE "posts"."status" IS NULL AND ("posts"."deleted_at" IS NULL) | |
# => [] | |
# > scope = Post.scoped.with_default_scope; nil | |
# => nil | |
# > scope.where_values | |
# => ["\"posts\".\"deleted_at\" IS NULL", #<Arel::Nodes::Equality:0x0000010a5ba300 @left=#<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x0000010a62cd10 @name="posts", @engine=Post(id: integer, title: string, body: text, deleted_at: datetime, created_at: datetime, updated_at: datetime, status: string), @columns=nil, @aliases=[], @table_alias=nil, @primary_key=nil>, name=:status>, @right=nil>] | |
# > scope.where_values.shift | |
# => "\"posts\".\"deleted_at\" IS NULL" | |
# > scope.all | |
# Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."status" IS NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
間違えて連投してしまいました・・・すみません