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

Foreign key string are not properly evolved to ObjectIds in #where for polymorphic relations

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0
    • Affects Version/s: 5.1.3
    • Component/s: None
    • None

      class Movie
        include Mongoid::Document
        has_many :ratings, as: :ratable
      end
      
      class Rating
        include Mongoid::Document
        belongs_to :ratable, polymorphic: true
      end
      

      When querying on a polymorphic foreign key string:

      Rating.where(ratable_id: "56cf07ccf1286e1286530b03")
      => #<Mongoid::Criteria
        selector: {"ratable_id"=>"56cf07ccf1286e1286530b03"}
        options:  {}
        class:    Rating
        embedded: false>
      

      It expected:

      Rating.where(ratable_id: "56cf07ccf1286e1286530b03")
      => #<Mongoid::Criteria
        selector: {"ratable_id"=>BSON::ObjectId('56cf07ccf1286e1286530b03')}
        options:  {}
        class:    Rating
        embedded: false>
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            bell.tree819@gmail.com Tomoyuki Suzuki
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: