mongodb/mongoid · error · Mongoid::Errors::MixedRelations

Referencing a(n) %{embedded} document from the %{root} docum

Error message

Referencing a(n) %{embedded} document from the %{root} document via a non-embedded association is not allowed since the %{embedded} is embedded.

What it means

Error "Referencing a(n) %{embedded} document from the %{root} document via a non-embedded association is not allowed since the %{embedded} is embedded." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/association/proxy.rb:152

      # Whether the proxy can forward the method to the target.
      #
      # @param [ String | Symbol ] name The name of the method.
      # @param [ Object... ] *args The +respond_to?+ arguments.
      #
      # @api private
      ruby2_keywords def respond_to_missing?(name, *args)
        _target.respond_to?(name, *args)
      end

      # When the base document illegally references an embedded document this
      # error will get raised.
      #
      # @example Raise the error.
      #   relation.raise_mixed
      #
      # @raise [ Errors::MixedRelations ] The error.
      def raise_mixed
        raise Errors::MixedRelations.new(_base.class, _association.klass)
      end

      # When the base is not yet saved and the user calls create or create!
      # on the association, this error will get raised.
      #
      # @example Raise the error.
      #   relation.raise_unsaved(post)
      #
      # @param [ Document ] doc The child document getting created.
      #
      # @raise [ Errors::UnsavedDocument ] The error.
      def raise_unsaved(doc)
        raise Errors::UnsavedDocument.new(_base, doc)
      end

      # Executes a callback method
      #
      # @example execute the before add callback

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/association/proxy.rb:152 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/46446ec0d57ea643. Report an issue: GitHub.