Forum: Ruby on Rails How to truncate a table from a rake file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7759594c66801d6f311ff38fd3ddef2a?d=identicon&s=25 Chris Gunnels (ballhogjoni)
on 2009-03-17 20:36
I am new to rails and want to figure out the syntax for truncating a
table using a rake file. Any ideas? thanks in advance!
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (conradwt)
on 2009-03-17 20:51
(Received via mailing list)
On Tue, Mar 17, 2009 at 12:36 PM, Chris Gunnels <
rails-mailing-list@andreas-s.net> wrote:

>
> I am new to rails and want to figure out the syntax for truncating a
> table using a rake file. Any ideas? thanks in advance!


Hi, what do you mean truncate a table?  Do you mean delete the contents
of
the table or
delete the table?

-Conrad
7759594c66801d6f311ff38fd3ddef2a?d=identicon&s=25 Chris Gunnels (ballhogjoni)
on 2009-03-17 20:58
Conrad Taylor wrote:
> On Tue, Mar 17, 2009 at 12:36 PM, Chris Gunnels <
> rails-mailing-list@andreas-s.net> wrote:
>
>>
>> I am new to rails and want to figure out the syntax for truncating a
>> table using a rake file. Any ideas? thanks in advance!
>
>
> Hi, what do you mean truncate a table?  Do you mean delete the contents
> of
> the table or
> delete the table?
>
> -Conrad

delete the contents of the table
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-17 23:09
(Received via mailing list)
On Mar 17, 7:58 pm, Chris Gunnels <rails-mailing-l...@andreas-s.net>
wrote:
> > delete the table?
>
> > -Conrad
>
> delete the contents of the table

If you make your task depend on the magic :environment task then
activerecord will be loaded with your database configuration (and you
models etc.) and you can just do MyModel.connection.execute "..." as
you would have normally or just SomeModel.delete_all if you don't care
about the difference between truncate and deleting all rows.

Fred
This topic is locked and can not be replied to.