inverse_of on belongs_to does not properly prevent InvalidSetPolymorphicRelation

XMLWordPrintableJSON

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

      As per the classic example for how to get an InvalidSetPolymorphicRelation:

      class Face
      include Mongoid::Document

      has_one :left_eye, class_name: "Eye", as: :eyeable
      has_one :right_eye, class_name: "Eye", as: :eyeable
      end

      class LeftEye
      include Mongoid::Document

      belongs_to :eyeable, polymorphic: true, inverse_of: :left_eye
      end

      class RightEye
      include Mongoid::Document

      belongs_to :eyeable, polymorphic: true, inverse_of: :right_eye
      end

      eye = LeftEye.new
      face = Face.new
      eye.eyeable = face # Raises Mongoid::Errors::InvalidSetPolymorphicRelation

      If we add an extra class and specify which relationship we're referring to (inverse_of), it still blows up. Should this not be valid?

              Assignee:
              Unassigned
              Reporter:
              ryanmcgarvey
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: