Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using acts-as-dag with acts_as_list #26

Open
MarkMT opened this issue May 5, 2019 · 0 comments
Open

Using acts-as-dag with acts_as_list #26

MarkMT opened this issue May 5, 2019 · 0 comments

Comments

@MarkMT
Copy link

MarkMT commented May 5, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant