Tom Maxwell
Tom Maxwell

Reputation: 9573

How to delete all posts from my PostgreSQL table?

I'm building a Rails app in which one of the functions is that the user can write journal entries and save them. I'd like to remove every journal entry from the respective PostgreSQL table they're in. How do I do this?

Upvotes: 0

Views: 151

Answers (2)

Mischa
Mischa

Reputation: 43318

If you don't care about callbacks and just want to delete everything in the table, you can use delete_all:

JournalEntry.delete_all

If you do want callbacks executed, you can use destroy_all:

JournalEntry.destroy_all

Upvotes: 1

hd1
hd1

Reputation: 34677

# assuming your journal entries are a model named Entry
Entry.find(:all).each { |e| e.destroy! }

Probably not the most efficient way, but it will do what you ask.

Upvotes: 1

Related Questions