Unfortunately it seems this excellent gem is no longer being actively maintained, but I mention the following here for the benefit of anyone else who happens to use it and may run into the same problem...
If using acts-as-dag with acts_as_list, e.g. to allow sibling links to be ordered, it is important that in the link model definition acts_as_dag_links be called before acts_as_list.
Explanation -
acts_as_list adds a before_destroy callback to the link model that causes a link record to be reloaded from the database before it is destroyed:
before_destroy :reload, unless: Proc.new { new_record? || destroyed_via_scope? || act_as_list_no_update? }
However acts-as-dag also has a destroy callback:
before_destroy :destroyable!, :perpetuate
perpetuate uses rewire_crossing to obtain other links affected by the destruction of a direct link and to manipulate the count attribute of each one in memory in order to act as a flag to determine what subsequently happens to it in push_associated_modification!. In the case where the direct link is being destroyed, associated indirect links will also be destroyed by push_associated_modification!. However the before_destroy callback above then causes destroyable! to be called on that indirect link, which also checks the count attribute that was modified by perpetuate to ensure that the link is in fact destroyable?.
Here is where the problem occurs - if acts-as-list is called before acts_as_dag_links, the reload callback will fire before destroyable! and the unsaved modification that perpetuate made to the count attribute will be lost. The result is that destroyable? will fail and destroyable! will throw an exception.
The solution is simply to ensure that acts_as_dag_links is called before acts_as_list.
Unfortunately it seems this excellent gem is no longer being actively maintained, but I mention the following here for the benefit of anyone else who happens to use it and may run into the same problem...
If using acts-as-dag with acts_as_list, e.g. to allow sibling links to be ordered, it is important that in the link model definition
acts_as_dag_linksbe called beforeacts_as_list.Explanation -
acts_as_list adds a
before_destroycallback to the link model that causes a link record to be reloaded from the database before it is destroyed:However acts-as-dag also has a destroy callback:
perpetuateusesrewire_crossingto obtain other links affected by the destruction of a direct link and to manipulate thecountattribute of each one in memory in order to act as a flag to determine what subsequently happens to it inpush_associated_modification!. In the case where the direct link is being destroyed, associated indirect links will also be destroyed bypush_associated_modification!. However thebefore_destroycallback above then causesdestroyable!to be called on that indirect link, which also checks thecountattribute that was modified byperpetuateto ensure that the link is in factdestroyable?.Here is where the problem occurs - if
acts-as-listis called beforeacts_as_dag_links, thereloadcallback will fire beforedestroyable!and the unsaved modification thatperpetuatemade to thecountattribute will be lost. The result is thatdestroyable?will fail anddestroyable!will throw an exception.The solution is simply to ensure that
acts_as_dag_linksis called beforeacts_as_list.