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

model callbacks fail if referenced models not prepended with :: #503

Open
drj17 opened this issue Jul 2, 2021 · 1 comment
Open

model callbacks fail if referenced models not prepended with :: #503

drj17 opened this issue Jul 2, 2021 · 1 comment

Comments

@drj17
Copy link

drj17 commented Jul 2, 2021

Expected behavior

Referencing related models in callbacks doesn't cause any issues.

Actual behavior

I have a method in a model Behavior that creates related records that is called in an after_create callback.

      if EngagementQuestion.count.zero?
        EngagementQuestion.create!(
          position: 0,
          behavior: self,
          organization: Organization.current
        )
      else
        EngagementQuestion.create!(
          position: EngagementQuestion.maximum(:position) + 1,
          behavior: self,
          organization: Organization.current
        )
      end

Whenever I create the behavior using forest, in development I get ArgumentError Exception: A copy of Behavior has been removed from the module tree but is still active!, in production I just get "Unknown Error". I have noticed that if I prepend every model with :: (i.e. ::EngagementQuestion) I can at least get past this, but it still fails because the behavior contains translations that are automatically created by the globalize gem in a separate callback, and this fails as well (I'm assuming for the same reason)

Context

  • Package Version: 6.6.2
  • Rails Version: 5.2
  • Database Dialect: PostgreSQL
  • Database Version: 12
@drj17
Copy link
Author

drj17 commented Jul 2, 2021

I can confirm that this does not happen in Rails 6.1

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

No branches or pull requests

2 participants