Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2362

Inverse field name stored on every polymorphic child

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.6
    • Affects Version/s: None
    • Component/s: None

      Mongoid 3.0.5 stores the inverse field name with every child record on polymorphic has_many associations, even when it's unnecessary.

      require 'test/unit'
      require 'mongoid'
      
      Mongoid.sessions = { default: { database: 'pmift', hosts: ['localhost:27017'] } }
      
      class PolymorphicInverseFieldTest < Test::Unit::TestCase
        class Event
          include Mongoid::Document
          belongs_to :eventable, polymorphic: true
        end
      
        class Opened < Event
        end
      
        class Door
          include Mongoid::Document
          has_many :events, as: 'eventable'
        end
      
        def setup
          @door = Door.create
          @event= Opened.new
          @door.events << @event  end
      
        def teardown
          Door.delete_all
          Event.delete_all
        end
      
        def test_should_not_have_inverse_field
          assert_nil @event.eventable_field
        end
      
        def test_should_not_query_for_inverse_field
          assert_nil @door.events.criteria.selector['eventable_field']
        end
      end
      

            Assignee:
            durran Durran Jordan
            Reporter:
            alexkwolfe Alex Wolfe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: