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

Improve support for Devise in apps with multiple ORMs loaded #5576

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

carlosantoniodasilva
Copy link
Member

Devise is able to work with a specific ORM, either Active Record or Mongoid, but nothing stops apps from using multiple ORMs within the same application -- they just need to pick one to use with Devise. That's generally determined by the require that is added to the Devise initializer, that will load up either ORM's extensions so you can call things like devise on your model to set it up.

However, some conditional logic in Devise, more specifically around dirty tracking, was only considering having Active Record loaded up after a certain version, to determine which methods to call in parts of the implementation. In a previous change we refactored all that dirty tracking code into this OrmDirtyTracking module to make it easier to view all the methods that were being conditionally called, and now we're repurposing this into a more generic Orm module (that's nodoc'ed by default) so that upon including it, we can conditionally include the proper dirty tracking extensions but also check whether the including model is really Active Record or not, so we can trigger the correct dirty tracking behavior for Mongoid as well if both are loaded on the same app, whereas previously the Mongoid behavior would always use the new Active Record behavior, but support may differ.

While we are also working to ensure the latest versions of Mongoid are fully running with Devise, this should improve the situation by giving apps with multiple ORMs loaded a chance to rely on some of these Devise bits of functionality better now that weren't working properly before without some monkey-patching on their end.

Closes #5539
Closes #4542

Devise is able to work with a specific ORM, either Active Record or
Mongoid, but nothing stops apps from using multiple ORMs within the same
application -- they just need to pick one to use with Devise. That's
generally determined by the require that is added to the Devise
initializer, that will load up either ORM's extensions so you can call
things like `devise` on your model to set it up.

However, some conditional logic in Devise, more specifically around
dirty tracking, was only considering having Active Record loaded up
after a certain version, to determine which methods to call in parts of
the implementation. In a previous change we refactored all that dirty
tracking code into this `OrmDirtyTracking` module to make it easier to
view all the methods that were being conditionally called, and now we're
repurposing this into a more generic `Orm` module (that's nodoc'ed by
default) so that upon including it, we can conditionally include the
proper dirty tracking extensions but also check whether the including
model is really Active Record or not, so we can trigger the correct
dirty tracking behavior for Mongoid as well if both are loaded on the
same app, whereas previously the Mongoid behavior would always use the
new Active Record behavior, but support may differ.

While we are also working to ensure the latest versions of Mongoid are
fully running with Devise, this should improve the situation by giving
apps with multiple ORMs loaded a chance to rely on some of these Devise
bits of functionality better now that weren't working properly before
without some monkey-patching on their end.

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

Successfully merging this pull request may close these issues.

undefined method `will_save_change_to_email?' for User
1 participant