10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

論理削除されたデータを検索する

Last updated at Posted at 2017-12-19

paranoiaってgemを使ってるのだが、いっつも忘れるので、メモ

  • 論理削除されたデータも「含める」

  • Model.with_deleted

  • 論理削除されたデータのみ

  • Model.only_deleted

この後ろに普通にwhereとかができる

> User.with_deleted.find 2
=> #<ActiveRecord::Relation [#<User id: 2, code: "admin2", name: "管理者2">

> User.with_deleted.where(code: "admin")
=> #<ActiveRecord::Relation [#<User id: 1, code: "admin", name: "管理者">

論理削除されたデータをModel.restore!で戻せるらしいけど、リレーションとかどうなるんだろうかが良く分からなかった。

paranoiについては以下のサイトにめちゃくちゃ詳しく書かれています。ありがとうございます。
http://www.task-notes.com/entry/20170813/1502618254

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?