1

I have a list of Accounts that get called throught the paranoid gem this in the accounts_controller: @deleted_accounts_count = Account.only_deleted.count, or

@deleted_accounts = Account.only_deleted.paginate(
          total_entries: @deleted_accounts_count, 
          page: params[:page], 
          per_page: 10
        )

Anyhow. I can call this list through the console fine in the console, but I'm trying to call a specific Account and hard-delete (really_destroy) it - every time I try to call it using its name, id (327) or its deleted_at attribute I get an empty object.

Account.only_deleted.where(deleted_at:"2018-07-25 07:39:57")
[■]   Account Load (1.7ms)  SELECT "accounts".* FROM "accounts" WHERE ("accounts"."deleted_at" IS NOT NULL) AND "accounts"."deleted_at" = $1  [["deleted_at", "2018-07-25 07
:39:57"]]
=> #<ActiveRecord::Relation []>


irb(main):008:0> Account.only_deleted.where(id:327)
[■]   Account Load (1.0ms)  SELECT "accounts".* FROM "accounts" WHERE ("accounts"."deleted_at" IS NOT NULL) AND "accounts"."id" = $1  [["id", 327]]
=> #<ActiveRecord::Relation []>
irb(main):009:0> Account.only_deleted.find(id:327)
[■]   Account Load (1.1ms)  SELECT  "accounts".* FROM "accounts" WHERE ("accounts"."deleted_at" IS NOT NULL) AND "id"."id" = 327 LIMIT 1
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "id"
LINE 1: ..." WHERE ("accounts"."deleted_at" IS NOT NULL) AND "id"."id" ...
                                                             ^
: SELECT  "accounts".* FROM "accounts" WHERE ("accounts"."deleted_at" IS NOT NULL) AND "id"."id" = 327 LIMIT 1

How do I call this deleted account from the soft-deleted list in order to apply the method I need?

Boucherie
  • 541
  • 4
  • 20
  • 1
    `Account.only_deleted.where(id:327).first` Or `Account.only_deleted.find(327)` should both have been sufficient. Are you sure the data reported is accurate? What is the output of `Account.find(327)`? – engineersmnky May 10 '19 at 20:22
  • `Account.find(327)` returns `ActiveRecord::RecordNotFound: Couldn't find Account with 'id'=327 [WHERE "accounts"."deleted_at" IS NULL]`. I can see it when I pull up the `Account.only_deleted` list though. – Boucherie May 10 '19 at 21:11
  • @engineersmnky - Assuming that I need to account for the IS NULL part; how can I uncover that? – Boucherie May 10 '19 at 21:33
  • 1
    What does `Account.only_deleted.find(327)` return? – engineersmnky May 10 '19 at 22:51
  • Hey, that worked! Submit answer? – Boucherie May 10 '19 at 23:01

0 Answers0