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

Allow id to be a regular field in models (not an alias of _id)

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.3.0
    • Affects Version/s: 7.0.5
    • Component/s: Attributes
    • None
    • Environment:
      MongoDB 3.6, Rails 5.2.1, Mongoid 7.0.5
    • Fully Compatible

      Original title: A field called "id" can not be set or updated with Document#create or Document#update

      I am trying to access an existing database, which has an "id" field that is separate from the "_id" field, and is application managed.

      My document definition looks like this:

      class Instance
        include Mongoid::Document
      
        self.aliased_fields.delete("id") # see MONGOID-2031
        store_in collection: 'app_instances'
      
        field :id, type: String
      
        field :name, type: String
        field :update_time, type: Float
      end
      

      With this code, querying works, at least, but inserting/updating does not.

       

      Is there a similar monkey patch to the one recommended in MONGOID-2031, or would this be even more of a mess?

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            fridtjofmund@icloud.com Fridtjof Mund
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: