Did the migration actually work? Can you see the constraint in the
database?
Make sure you don't have any other constraints that would restrict the
delete
e.g. ON DELETE RESTRICT or ON DELETE NO ACTION

You could also try to set up the constraint using "execute" in the
migration:

def self.up
  execute "ALTER TABLE `gardens` DROP FOREIGN KEY `gardens_user_fkey`"
  execute "ALTER TABLE `gardens` ADD CONSTRAINT `gardens_user_fkey`
    FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
    ON DELETE CASCADE ON UPDATE CASCADE"
end

def self.down
  execute "ALTER TABLE `gardens` DROP FOREIGN KEY `gardens_user_fkey`"
end

If that doesn't work for some reason you could try to do something
similar
in the table triggers. But it should work fine.

Regards,
Kerry


On Oct 25, 8:17 am, Erik Pukinskis <[email protected]> wrote:
> Hey all,
>
> I've been trying find a way to set up relatively fast cascading of
> deletions across multiple model associations with no luck.  It seems
> like most people just throw :dependent => :destroy into their models,
> but that's dog slow, especially if you've got a big table with lots of
> rows (I have a 100k item table joined to a 1m item table, and I need
> to delete a large number of those).
>
> So obviously I need to do this in the database, but I can't really
> find any way to do it.  I've got a User who has a Garden who has many
> Crops.  And I've got the following in my migrations:
>
>   add_foreign_key :gardens, :user_id, :users, :id, :on_delete =>
> :cascade, :name => "gardens_user_fkey"
>   add_foreign_key :crops, :garden_id, :gardens, :id, :on_delete =>
> :cascade, :name => "crops_garden_fkey"
>
> That's using the redhillonrails_core plugin
> (http://github.com/weplay/redhillonrails_core).  I thought that would
> do it, but when I delete a user, the garden and crops stick around.
>
> There's not much documentation on the web for this issue.... seems
> like most people are only deleting a row or two in their apps, and
> just use the ActiveRecord facilities and accept that it'll take a
> little bit of time.
>
> Anyone else have any experience with this?
>
> Best,
> Erik

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to