我在 Rails 中有一个具有 one_to_many 关系的模型。当我删除父亲时,我想删除所有孩子。我该怎么做?我想在删除用户时删除所有订单及其商品
我的模型是:
class User < ActiveRecord::Base
has_many :orders, :foreign_key => "id_user"
end
class Order < ActiveRecord::Base
has_many :order_items, :foreign_key => "id_pedido"
belongs_to :user, :foreign_key => "id_usuer"
end
class OrderItem < ActiveRecord::Base
belongs_to :order, :foreign_key => "id_pedido"
end