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

Non-block form of persistence context #with

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Dev Exp
    • None

      https://jira.mongodb.org/browse/MONGOID-5472 describes the original requested use case: when a model is loaded with a runtime-overridden persistence context, it should be by default saved using that persistence context, i.e. the write should be to where the instance came from.

      The syntax shown in https://jira.mongodb.org/browse/MONGOID-5472 retains the block form of #with, which is awkward:

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

      It would be more convenient if #with didn't require the block in this case:

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

      See discussion and partial patch in https://github.com/mongodb/mongoid/pull/4556.

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

              Created:
              Updated: