-
Type: Task
-
Resolution: Done
-
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