active_record-acts_as
active_record-acts_as copied to clipboard
Actable model is saved twice
actable.save
will trigger two update queries and the after_save
callback is called twice.
I think this is because of the bi-directional auto_save: true
on actings as and actable model.
We need both autosave
s AFAICS. Happy to remove one if there's an alternative though! :)
not asking to remove one, but the issue is after_save
callbacks are called twice, and duplicated queries are generated, isn't that an issue with the gem ?
Yeah sure, it might be. If you know how to fix it, please submit a PR!
@manuelmeurer We have a workaround that uses after_save
instead of autosave
and that fixed the issue on our project, not sure if you are interested in the way we are doing.
however, I think we should open the issue until someone submits a PR, what you think ? 😄
Can you post the code of your workaround? I'm happy to try it out to see if it fixes the problem! 😄
@manuelmeurer Thanks ! 😄
Here's the commit: https://github.com/Coursemology/active_record-acts_as/commit/ca24c95b8f1a1ce2f00fb18cf93ff000358e05e3
We have tested and used in our production product ( 80+ tables/models ) and turns out to be pretty stable.
Could you test if this is still a problem with the current gem version (2.2.0)?
I just tried it out on the console and the after_save
callbacks on the supermodel and submodel were only called once each.
@manuelmeurer Can let me know which rails version that you were testing on ?
4.2.8
Let you know first @manuelmeurer, it still happens to us with 2.2.1 in rails 4.2.8.
I will see if can get an example app to reproduce this, but that will take some time...