-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
None
Currently, with_session is called on Document class and instance. Examples:
Person.with_session { Person.all.first; Car.all.to_a,first; Dog.all.first }
# or
bob = Person.new
bob.with_session { ... }
This syntax is very awkward, because you must call "with_session" on one document, but then you can call other documents in the same scope as long as they share the same client. It would be much more intuitive if we called it on the Mongo::Client instead, which is the fundamental "isolation unit" of the session.
Mongoid.clients['default'].with_session { ... } # or Person.persistence_context.client.with_session { ... }
(We could keep the existing syntax as well).
This change would require added thread storage to Mongo library. Alternatively, we could add a face Mongoid::Client which subclasses/wraps Mongo::Client and adds this method. This might make things a lot cleaner, as it is also awkward that Mongoid::Clients is an array of Mongo::Client.