Before_destroy not called

I have a situation where it seems rails should delete dependent
records but does not:

class Order < ActiveRecord::Base
has_many :line_items, :dependent => :destroy

class LineItem < ActiveRecord::Base
belongs_to :order

This deletes the order but not the line item. I did a little debugging
and see that rails adds the code (associations.rb):

      case reflection.options[:dependent]
        when :destroy, true
          module_eval "before_destroy '#{}.each { |

o| o.destroy }’"

but if I add a before_destroy to Order, it is never called. There was
another post on this but I didn’t really see an explanation for this.
More of a workaround.

Rails is great and all, but running into what seems to be very simple
cases that don’t work and having to step thru very cryptic rails code
isn’t much fun.

I guess I’ll add cascade/delete to the database tables…

delete skips any callbacks, use destroy if you want the callbacks to get

dailer wrote:

        when :destroy, true

I guess I’ll add cascade/delete to the database tables…


William P.
[email protected]

ugh. that was too easy.