When destroying something with a has_many association, are the associated records destroyed first? It doesn''t look like it. Is this a bug, or intended behavior? An example: class Stack has_many :cards, :order => "position", :dependent => true, :conditions => ''position > 0'' end # The Card class/table has a foreign key constraint on stack_id. # That means the stack can''t be destroyed before the cards are. # When calling destroy(), I want the cards (the dependent objects) # to be deleted first. They are not. Stack.destroy(1) # SQL ERROR: ''update or delete on "stacks" violates foreign key constraint "cards_stack_id_fkey" on "cards"''. Jim -- Jim Menard, jimm-Xhj3G7Rj6JI@public.gmane.org, http://www.io.com/~jimm "Brought to you again by the Department of Redundancy Department." -- Firesign Theatre
Jim Menard wrote:> When destroying something with a has_many association, are the associated > records destroyed first? It doesn''t look like it. Is this a bug, or intended > behavior? An example:Never mind; the problem was caused because a Stack has another card that wasn''t marked as dependent. That caused the foreing key constraint problem.> > class Stack > has_many :cards, :order => "position", :dependent => true, > :conditions => ''position > 0''belongs_to :background_card, :foreign_key => "background_card_id", :class_name => "Card"> end >Jim -- Jim Menard, jimm-Xhj3G7Rj6JI@public.gmane.org, http://www.io.com/~jimm "Brought to you again by the Department of Redundancy Department." -- Firesign Theatre