From 614c61cc2c0509085b8ff799019e6b477610ef69 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Mon, 29 Jul 2024 17:03:45 -0600 Subject: [PATCH] need to register subclasses, too --- lib/mongoid/traversable.rb | 5 +++++ spec/mongoid/association/referenced/belongs_to/proxy_spec.rb | 1 + .../association/referenced/has_many/buildable_spec.rb | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/lib/mongoid/traversable.rb b/lib/mongoid/traversable.rb index 7a4f999a9a..e53bfe164c 100644 --- a/lib/mongoid/traversable.rb +++ b/lib/mongoid/traversable.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'mongoid/fields/validators/macro' +require 'mongoid/model_resolver' module Mongoid # Mixin module included in Mongoid::Document to provide behavior @@ -32,6 +33,10 @@ def hereditary? # rubocop:disable Metrics/AbcSize def inherited(subclass) super + + # Register the new subclass with the resolver subsystem + Mongoid::ModelResolver.register(subclass) + @_type = nil subclass.aliased_fields = aliased_fields.dup subclass.localized_fields = localized_fields.dup diff --git a/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb b/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb index a12ef78a6c..f3f5f6c66a 100644 --- a/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +++ b/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb @@ -2,6 +2,7 @@ # rubocop:todo all require "spec_helper" +require 'support/models/canvas' require_relative '../belongs_to_models.rb' describe Mongoid::Association::Referenced::BelongsTo::Proxy do diff --git a/spec/mongoid/association/referenced/has_many/buildable_spec.rb b/spec/mongoid/association/referenced/has_many/buildable_spec.rb index f716226674..e1fb371a13 100644 --- a/spec/mongoid/association/referenced/has_many/buildable_spec.rb +++ b/spec/mongoid/association/referenced/has_many/buildable_spec.rb @@ -100,6 +100,10 @@ Post.where(association.foreign_key => object, 'ratable_type' => 'Rating') end + before do + Post.belongs_to :ratable, polymorphic: true + end + it "adds the type to the criteria" do expect(documents).to eq(criteria) end