]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
doc updates, added 'save' method to assignmapper
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 May 2006 16:59:07 +0000 (16:59 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 May 2006 16:59:07 +0000 (16:59 +0000)
doc/build/content/plugins.txt
doc/build/content/unitofwork.txt
lib/sqlalchemy/ext/assignmapper.py

index 1502d4c01395147813310c9620b8895a2bc201be..cb1707758a69b7f618849f3f11a4a8845869e56f 100644 (file)
@@ -84,7 +84,7 @@ The `objectstore` is an instance of `SessionContext`, available in the `sqlalche
 
 #### Attaching Mappers to their Class {@name=attaching}
 
-With `get_session()` handling the details of providing a `Session` in all cases, the `assign_mapper` function provides some of the functionality of `Query` and `Session` directly off the mapped instances themselves.  This is a "monkeypatch" function that creates a primary mapper, attaches the mapper to the class, and also the  methods `get, get_by, select, select_by, selectone, selectfirst, commit, expire, refresh, expunge` and `delete`:
+With `get_session()` handling the details of providing a `Session` in all cases, the `assign_mapper` function provides some of the functionality of `Query` and `Session` directly off the mapped instances themselves.  This is a "monkeypatch" function that creates a primary mapper, attaches the mapper to the class, and also the  methods `get`, `select`, `select_by`, `selectone`, `get_by`, `join_to`, `join_via`, `flush`, `delete`, `expire`, `refresh`, `expunge`, `merge`, `update`, `save`, and `save_or_update`:
 
     {python}
     # "assign" a mapper to the User class/users table
@@ -101,6 +101,8 @@ With `get_session()` handling the details of providing a `Session` in all cases,
     # flush the changes on a specific object
     myotheruser.flush()
 
+A more generic version of `assign_mapper` that works with any `SessionContext` is available in the [plugins_assignmapper](rel:plugins_assignmapper) plugin.
+
 #### Engine Strategy Set to threadlocal By Default {@name=engine}
 
 The `threadlocal` mod also establishes `threadlocal` as the default *strategy* when calling the `create_engine()` function.  This strategy is specified by the `strategy` keyword argument to `create_engine()` and can still be overridden to be "`plain`" or "`threadlocal`" explicitly.
@@ -181,7 +183,24 @@ The construction of each `Session` instance can be customized by providing a "cr
     # get the session corresponding to "scope2", bound to engine "someengine":
     session = ctx.current
     
+### assignmapper
+
+**Author:** Mike Bayer
+
+This is a generic version of the `assign_mapper` function present in the [plugins_threadlocal](rel:plugins_threadlocal) mod.  It requires an explicit [plugins_sessioncontext](rel:plugins_sessioncontext).
 
+    {python}
+    import sqlalchemy
+    from sqlalchemy.ext.sessioncontext import SessionContext
+    from sqlalchemy.ext.assignmapper import assign_mapper
+    
+    # session context
+    ctx = SessionContext(sqlalchemy.create_session)
+    
+    # assign mapper to class MyClass using table 'sometable', getting
+    # Sessions from 'ctx'.
+    assign_mapper(ctx, MyClass, sometable)
+    
 ### ActiveMapper
 
 **Author:** Jonathan LaCour
@@ -243,11 +262,11 @@ More discussion on ActiveMapper can be found at [Jonathan LaCour's Blog](http://
 
 **Author:** Jonathan Ellis
 
-SqlSoup creates mapped classes on the fly from tables.  It is essentially a nicer version of the "row data gateway" pattern.
+SqlSoup creates mapped classes on the fly from tables, which are automatically reflected from the database based on name.  It is essentially a nicer version of the "row data gateway" pattern.
 
     {python}
     >>> from sqlalchemy.ext.sqlsoup import SqlSoup
-    >>> soup = SqlSoup('sqlite://filename=:memory:')
+    >>> soup = SqlSoup('sqlite:///')
 
     >>> users = soup.users.select()
     >>> users.sort()
index 0e0a534e2e31412e010561d44ff7d35ab92cea6c..3bc1c4e9677e5d75d1e10511d10a6640c1eae986 100644 (file)
@@ -216,7 +216,7 @@ It also can be called with a list of objects; in this form, the flush operation
     {python}
     # saves only user1 and address2.  all other modified
     # objects remain present in the session.
-    session.flush(user1, address2)
+    session.flush([user1, address2])
     
 This second form of flush should be used carefully as it will not necessarily locate other dependent objects within the session, whose database representation may have foreign constraint relationships with the objects being operated upon.
 
index 07ba95a694ae8d176e3853ea2174db9e18aa4e76..f7b093e9de4def4f695bed83d9bd5b2c91afa8e1 100644 (file)
@@ -33,5 +33,5 @@ def assign_mapper(ctx, class_, *args, **kwargs):
     class_.mapper = m
     for name in ['get', 'select', 'select_by', 'selectone', 'get_by', 'join_to', 'join_via']:
         monkeypatch_query_method(ctx, class_, name)
-    for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'update', 'save_or_update']:
+    for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'save', 'update', 'save_or_update']:
         monkeypatch_objectstore_method(ctx, class_, name)