ruby-on-railsacts-as-listacts-as-paranoid

acts_as_list with paranoia gem


I have two models. The first ModelA is the parent of ModelB. ie ModelA has_many ModelB. [When modelA is destroyed, all its dependent ModelB's also gets destroyed due to dependent destroy Now I have acts_as_paranoid scope: :ModelA

With this,I also have acts_as_paranoid set up for both Models A&B.

Now when I am destroying ModelA, I don't wan't the callbacks in ModelB to be called when ModelB records gets destroyed.

Particularly, ModelB has something called as position as an attribute, which gets updated when ModelA gets paranoia destroyed which causes the position attribute of ModelB to change. I wan't the position not to change so that I can safely restore the ModelA with the same records and properties for ModelB which was there before.

Thanks.


Solution

  • As per the readme

    ModelB.acts_as_list_no_update do
      modela_instance.destroy
    end
    

    This should work. I wish I could test it, unfortunately don't have such setup. Let me know if any issues. Hope it helps..


    Update: syntax that worked for this case as in comments.

    ModelB.acts_as_list_no_update([ModelB]) do
      modela_instance.destroy
    end