i was refactoring our Item model, where we have 3 has_many with 3 mapping
models.
as we are not using InnoDB based foreign key constraint, we were searching
some sort of reliable solution,
which will take pressure in application layer instead of leaving it to the
database.
so later we introduced ":dependent" with has_may relation. here is our top
of Item model.
has_many :category_mappings, :dependent => :destroy
has_many :categories, :through => :category_mappings
has_many :property_values, :dependent => :destroy
has_many :properties, :through => :property_value
has_many :item_location_mappings, :dependent => :destroy
has_many :locations, :through => :item_location_mappings
our "dependent" flagship is destroying all related items in the item destroy
process which has introduced
our flexibility and reduced a lot of code to manage such stuff in a DRY(ied)
manner.
so the following unit test worked fine for us.
some bad side,
dependent delete each and every item one by one, which is big issue when you
have a big chunk of dependent data.
but that is not suppose to be common in every context. we have no problem
with this issue.
best of luck!
--
----------------------------------------------------
nhm tanveer hossain khan (hasan)
http://hasan.we4tech.com
----------------------------------------------------
mobile: +880 1713 090 511
----------------------------------------------------
"work for fun"
[Non-text portions of this message have been removed]