Hi,
I have a has_and_belongs_to relationship between 2 objects, order and
product. I’m getting a foreign key violation when trying to delete
Order. Is there a special way of deleting orders without deleting
products? (“has_many” has :dependant => :delete_all… does
“has_and_belongs_to” have something similar)
Trying:
Order.delete_all
Getting:
Mysql::Error: #23000Cannot delete or update a parent row: a foreign key
constraint fails: DELETE FROM orders
With associations:
class Order < ActiveRecord::Base
has_and_belongs_to_many :products
end
class Product < ActiveRecord::Base
has_and_belongs_to_many :orders
end
Thanks, Bart