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

Save models using the overridden persistence context used for their loading

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 9.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      In https://github.com/mongodb/mongoid/pull/4556, it was requested that Mongoid provides a way for model instances that were loaded using a runtime-altered persistence context to retain that persistence context so that they would be saved to their correct source.

      Current behavior when loading and saving using runtime-overridden persistence context:

      band = Band.with(collection: 'foo') { |cls| cls.first }
      # #with must be called again:
      Band.with(collection: 'foo') { band.save! }
      

      Desired behavior:

      band = Band.with(collection: 'foo') { |cls| cls.first }
      # saves to 'foo'
      band.save!
      

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: