-
Type: Task
-
Resolution: Won't Fix
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Consider the following (failing) example. Mongoid will coerce the SpecialPartner relationship into having property_type=SpecialPartner. This makes it hard to locate all objects of AccessControl type that belong to a Partner. We used to use the exact code below and overwrite property_type with Partner, which is no longer possible on HEAD.
ruby require "spec_helper" class Partner include Mongoid::Document has_one :access_control, as: :property end class SpecialPartner < Partner end class AccessControl include Mongoid::Document belongs_to :property, polymorphic: true end describe Mongoid do it "issue" do partner = SpecialPartner.create! acl = AccessControl.find_or_create_by({ property_type: 'Partner', property_id: partner.id }) acl.property_type.should == 'Partner' acl.reload acl.property_type.should == 'Partner' acl.reload acl.property.should == partner acl.property_type.should == 'Partner' end end
TBH I am 50/50 on whether this is a good idea. There're plenty of workarounds, such as storing something else on the model like parent_type, but I thought I'd bring it up.