Forum: Ruby on Rails Disabling FOREIGN KEYs in a Rake task

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.
77fec2b94c481ad3d2b2135b1f07ef5f?d=identicon&s=25 Marco Lazzeri (Guest)
on 2006-05-09 02:55
(Received via mailing list)
Hi,

How could I disable my database FOREIGN KEYs in a Rake task?
Or, how could I call the execute() method in a Rake task?

I'm trying to perform something like:

  task :delete_the_cippalippa => :environment do
    require RAILS_ROOT+'/lib/marsian.rb'
    # FIXME: execute() is undefined
    execute "SET FOREIGN_KEY_CHECKS = 0"
    Cippalippa.delete(-1)
    [..some more code..]
    # FIXME: as above
    execute "SET FOREIGN_KEY_CHECKS = 1"
  end

Thanks.

Cheers,
Marco
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2006-05-09 03:04
(Received via mailing list)
On May 8, 2006, at 5:54 PM, Marco Lazzeri wrote:
>     [..some more code..]
>     # FIXME: as above
>     execute "SET FOREIGN_KEY_CHECKS = 1"
>   end


ActiveRecord::Base.connection.execute '...'

Cheers,
jeremy
77fec2b94c481ad3d2b2135b1f07ef5f?d=identicon&s=25 Marco Lazzeri (Guest)
on 2006-05-09 03:11
(Received via mailing list)
On 09/05/06, Jeremy Kemper <jeremy@bitsweat.net> wrote:
> > How could I disable my database FOREIGN KEYs in a Rake task?
> > Or, how could I call the execute() method in a Rake task?
>
> ActiveRecord::Base.connection.execute '...'

Thanks Jeremy. It works perfectly!

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