Non-block form of persistence context #with

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Dev Exp
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
              Reporter:
              Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: