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

belongs_to in namespaced children fails to detect a non-namespaced association

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.1.0.rc0, 7.0.3
    • Affects Version/s: 7.0.2
    • Component/s: Associations
    • Labels:
      None

      MONGOID-4532 (Github PRĀ #4536) causes a regression in Mongoid 7.0.2.

      When a namespaced child model includes a belongs_to, 7.0.1 and prior assumed that association was not-namespaced.

      7.0.2 introduced a breaking change that now assumes that association is always namespaced inside the same module.

      Code to reproduce: https://gist.github.com/zarqman/d307ecf40a65fbe1b0fc71ea0d36ac69

      A workaround is to explicitly specify the :class_name for the association (as shown in the commented out line 40).

      Would it be possible for Mongoid's :class_name auto-detection to follow traditional Ruby semantics? That is, default to searching for Space::Other and if not found, then search for ::Other?

      If this isn't possible, then I would suggest reverting the change in PR #4536 since it is a code-breaking regression.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            tmorgan thomas morgan
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: