[Plugin: WP MVC] Deleting models with has_and_belongs_to_many association
-
So I have a category model which has the association of has_and_belongs_to_many with a product model and they have a join table ‘products_categories’ linking their primary keys.
A category can have many products associated with it and I built a custom interface similar to the has_many_dropdown form element to do so. Adding and removing products to the category works great, but deleting the category from the main category index page when it has products associated with it wont delete the category. It deletes fine when there are no linked products. Im assuming this has something to do with foreign key relationships in mysql.
Is this the intended behavior or does the wpmvc framework have a function which will loop through the join table and remove all associations before deleting the main model or do I need to do that myself? Its a little confusing that when I click delete and there are no errors and the flash message says deleted successfully but its still there in the table.
Ive been lookin in the core mvc_model class and I see the delete_dependent_association() function which gets called from the delete_all() function but it looks as if that only works for has_many associations, which my models down work unless they are has_and_belongs_to_many.
Any Help is appreciated.
Thanks!
- The topic ‘[Plugin: WP MVC] Deleting models with has_and_belongs_to_many association’ is closed to new replies.