Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4312

Includes does not work with specific classes

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 5.1.4
    • Component/s: None
    • None

      recently in Mongoid gem there have been added possibility to include nested models: User.includes(:address, friends: [:address, :followers]) (https://jira.mongodb.org/browse/MONGOID-4173)

      Lets say I have following models:

      class Pages::Continent
      has_many :contries, class_name: "Pages::Country"
      end

      class Pages::Country
      belongs_to :continent, class_name: "Pages::Continent"
      has_many :contries, class_name: "Pages::Cities"
      end

      class Pages::City
      belongs_to :continent, class_name: "Pages::Country"
      end
      While trying to select continents including countries and cities:

      @continents = Pages::Continent.includes(countries: [:cities])
      I receive the error: NameError (uninitialized constant Country) which probably means that it does not look for Pages::Country but just for Country model (however as you can see class_name attributes are specified for each model)

            Assignee:
            Unassigned Unassigned
            Reporter:
            maks Maks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: