When I try to delete a grandfather in a grandfather, father & son
relationship as in the following, the grandfather and all the
associated fathers are deleted, but the sons are left as orphans.
It seems ROR can do a 2-tier cascading delete, but fails on a 3-tier
cascading delete.

  create_table "galleries", :force => true do |t|
    t.string   "name"
  end

  create_table "gallery_images", :force => true do |t|
    t.integer  "gallery_id"
  end

  create_table "gallery_image_profiles", :force => true do |t|
    t.integer  "gallery_image_id"
    t.integer  "profile_id"
  end

model gallery.rb
class Gallery < ActiveRecord::Base
    has_many :gallery_images, :dependent =>:delete_all
end

model gallery_image.rb
class GalleryImage < ActiveRecord::Base
    belongs_to :gallery

    has_many :gallery_image_profiles, :dependent => :delete_all
end

model gallery_image_profile.rb
class GalleryImageProfile < ActiveRecord::Base
    belongs_to :gallery_image
    belongs_to :profile
end

controller: galleries_controller.rb
class GalleriesController < ApplicationController
  def destroy
    @gallery = Gallery.find(params[:id])
    @gallery.destroy
    redirect_to :action => 'list'
  end
end
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to