Solved.. automatic deletion just doesn''t work with
has_and_belongs_to_many.
I need to use has_many :through, :dependent => delete_all
Bart
On Jan 24, 10:05 pm, "Bart"
<b...-ERYYqGLKSZVWk0Htik3J/w@public.gmane.org>
wrote:> 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
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---