mongodb/mongoid · error · ArgumentError

The :fallback option for association '#{name}' on #{@owner_c

Error message

The :fallback option for association '#{name}' on #{@owner_class} must be a Proc or lambda.

What it means

Error "The :fallback option for association '#{name}' on #{@owner_class} must be a Proc or lambda." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/association/relatable.rb:427

        Association::Referenced::CounterCache.define_callbacks!(self)
      end

      def define_dependency!
        return unless dependent

        Association::Depending.define_dependency!(self)
      end

      def validate!
        @options.keys.each do |opt|
          unless self.class::VALID_OPTIONS.include?(opt)
            raise Errors::InvalidRelationOption.new(@owner_class, name, opt, self.class::VALID_OPTIONS)
          end
        end

        if @options.key?(:fallback)
          unless @options[:fallback].respond_to?(:call)
            raise ArgumentError,
                  "The :fallback option for association '#{name}' on " \
                  "#{@owner_class} must be a Proc or lambda."
          end

          if @options.key?(:autobuild)
            raise ArgumentError,
                  "The :fallback option for association '#{name}' on " \
                  "#{@owner_class} cannot be combined with :autobuild."
          end
        end

        [ name, :"#{name}?", :"#{name}=" ].each do |n|
          raise Errors::InvalidRelation.new(@owner_class, n) if Mongoid.destructive_fields.include?(n)
        end
      end

      def polymorph!
        return unless polymorphic?

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/association/relatable.rb:427 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/e4f5895a29c50fa5. Report an issue: GitHub.