Skip to content

NameError: uninitialized constant Mobility::ActiveRecord::Base #69

@madis

Description

@madis

When Mobility is loaded for ActiveRecord, it includes Mobility::ActiveRecord module

model_class.include(ActiveRecord) if model_class < ::ActiveRecord::Base

If the ActiveRecord::Base subclass that now includes Mobility did something like the following before:

class MyModel < ActiveRecord::Base
  def my_method
    ActiveRecord::Base.uncached do
      # some code
    end
  end
end

It will get an exception raised:

NameError:
  uninitialized constant Mobility::ActiveRecord::Base

It will get an exception because ActiveRecord is found on Mobility module first (the original ActiveRecord from rails is further down in the ancestors chain.

The fix on the user's side would be to qualify top level lookup with ::ActiveRecord but I don't know how happy the users of Mobility would be if they had to do it.

Another would be to rename the ActiveRecord module in Mobility, which would kind of diminish the descriptiveness.

Do you have other suggestions on how to approach this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions