Now you can do tablename.truncate. This was not incorporated into AR as a patch because SQLite does not support truncate statements. See this pull request for more detail:
I'm releasing this as a gem, so I don't have to add it to my config/initializers.
This has so far only been tested for mysql2 adapater/MySQL DB.
Why truncate versus delete * ? Its more performant and it resets the primary key ID to 1. Useful when you're re-seeding/testing.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install ar_truncator
If you have a model called Dummy, to truncate it do:
This will execute the following sql:
"Truncate tabel Dummies".
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request