Skip to content

Instantly share code, notes, and snippets.

@miyucy
Created October 12, 2012 18:14
Show Gist options
  • Save miyucy/3880636 to your computer and use it in GitHub Desktop.
Save miyucy/3880636 to your computer and use it in GitHub Desktop.
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
@ideomix
Copy link

ideomix commented Oct 15, 2012

scope = Post.scoped.with_default_scope; nil
質問ばっかりで本当に申し訳ありませんが
ここ、どういうことなんですか・・・?
びっくりなんですけど笑

@ideomix
Copy link

ideomix commented Oct 15, 2012

間違えて連投してしまいました・・・すみません

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment