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

Change DescendantLoader to handle non-AR classes in the models directory #16867

Merged

Commits on Jan 23, 2018

  1. Change DescendantLoader to handle non-AR classes in the models directory

    Class is patched by ActiveSupport to add the descendants method, so this change
    keeps our patching of ActiveSupport consistent across the board by also patching
    Class.  This was handled specifically for ActsAsArModel previously, but there
    are other classes that also might need this functionality such as Authenticator.
    Individually adding new classes is not maintainable and also not expected, so
    this is handled generically via a patch to Class.
    
    We still need to keep our ActiveRecord::Base patch because due to timing.  By
    the time we hit the patching lines, ActiveRecord::Base has already been further
    modified with ActiveSupport::DescendantsTracker via prepend, and if we were to
    rely on the Class patch, then we wouldn't be able to get ahead of
    DescendantsTracker.
    
    Visually, the singleton_class' ancestors chain looks like this for Object:
    
        [
          #<Class:Object>,
          ...
          DescendantLoader::ArDescendantsWithLoader,
          Class,
          ...
          Object,
          ...
        ]
    
    but looks like this for ActiveRecord::Base (if we were to rely on the
    Class patch only):
    
        [
          #<Class:ActiveRecord::Base>,
          ...
          ActiveSupport::DescendantsTracker,
          ...
          #<Class:Object>,
          ...
          DescendantLoader::ArDescendantsWithLoader,
          Class,
          ...
          Object,
          ...
        ]
    
    Thus ActiveSupport::DescendantsTracker's definition of descedants wins, unless
    we patch ActiveRecord::Base directly.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1537299
    Fryguy committed Jan 23, 2018
    Configuration menu
    Copy the full SHA
    104416d View commit details
    Browse the repository at this point in the history