You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 beforeacts_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:
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.
The text was updated successfully, but these errors were encountered:
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 beforeacts_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:However acts-as-dag also has a destroy callback:
perpetuate
usesrewire_crossing
to obtain other links affected by the destruction of a direct link and to manipulate thecount
attribute 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_destroy
callback above then causesdestroyable!
to be called on that indirect link, which also checks thecount
attribute that was modified byperpetuate
to ensure that the link is in factdestroyable?
.Here is where the problem occurs - if
acts-as-list
is called beforeacts_as_dag_links
, thereload
callback will fire beforedestroyable!
and the unsaved modification thatperpetuate
made to thecount
attribute will be lost. The result is thatdestroyable?
will fail anddestroyable!
will throw an exception.The solution is simply to ensure that
acts_as_dag_links
is called beforeacts_as_list
.The text was updated successfully, but these errors were encountered: