mongodb/mongoid · error · Mongoid::Errors::InvalidRelation
Defining an association named '%{name}' is not allowed.
Error message
Defining an association named '%{name}' is not allowed. What it means
Error "Defining an association named '%{name}' is not allowed." thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/association/relatable.rb:440
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?
@owner_class.polymorphic = true
end
def create_extension!(&block)
return unless block
extension_module_name = "#{@owner_class.to_s.demodulize}#{name.to_s.camelize}RelationExtension"
silence_warnings do
@owner_class.const_set(extension_module_name, Module.new(&block))
end
@extension = "#{@owner_class}::#{extension_module_name}".constantize
endView on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/association/relatable.rb:440 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/99dbe17196120eb9.
Report an issue: GitHub.