Skip to content

Commit

Permalink
need to register subclasses, too
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Jul 29, 2024
1 parent 2bad8fd commit 614c61c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mongoid/traversable.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 614c61c

Please sign in to comment.