]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- restored old assign_mapper monkey patched query methods but with two differences:
authorGaëtan de Menten <gdementen@gmail.com>
Tue, 31 Jul 2007 14:54:28 +0000 (14:54 +0000)
committerGaëtan de Menten <gdementen@gmail.com>
Tue, 31 Jul 2007 14:54:28 +0000 (14:54 +0000)
   * added a deprecation warning
   * check if a method with that name already exist in the class
 - more foolproof deprecation warning for scalar kwarg

lib/sqlalchemy/ext/assignmapper.py
lib/sqlalchemy/sql.py

index 2380417020b3806c3c1c4590d12a0effd59d1cb5..cab5a9eae662c27f4fcfecb53f998e661af5e614 100644 (file)
@@ -1,7 +1,19 @@
 from sqlalchemy import util, exceptions
 import types
-from sqlalchemy.orm import mapper
+from sqlalchemy.orm import mapper, Query
     
+def _monkeypatch_query_method(name, ctx, class_):
+    def do(self, *args, **kwargs):
+        query = Query(class_, session=ctx.current)
+        util.warn_deprecated('Query methods on the class are deprecated; use %s.query.%s instead' % (class_.__name__, name))
+        return getattr(query, name)(*args, **kwargs)
+    try:
+        do.__name__ = name
+    except:
+        pass
+    if not hasattr(class_, name): 
+        setattr(class_, name, classmethod(do))
+
 def _monkeypatch_session_method(name, ctx, class_):
     def do(self, *args, **kwargs):
         session = ctx.current
@@ -41,7 +53,9 @@ def assign_mapper(ctx, class_, *args, **kwargs):
     if not hasattr(class_, 'query'): 
         class_.query = query()
     
-    for name in ['refresh', 'expire', 'delete', 'expunge', 'update']:
+    for name in ('get', 'filter', 'filter_by', 'select', 'select_by', 'selectfirst', 'selectfirst_by', 'selectone', 'selectone_by', 'get_by', 'join_to', 'join_via', 'count', 'count_by', 'options', 'instances'):
+        _monkeypatch_query_method(name, ctx, class_)
+    for name in ('refresh', 'expire', 'delete', 'expunge', 'update'):
         _monkeypatch_session_method(name, ctx, class_)
 
     m = mapper(class_, extension=extension, *args, **kwargs)
index b27e8237033edc86b7b650c34139f2c1aa3a3282..479f13a8a1100afd0cb216670d3dd3af2a4c5871 100644 (file)
@@ -214,9 +214,9 @@ def select(columns=None, whereclause=None, from_obj=[], **kwargs):
           rendered in the ``FROM`` clause of this select statement.
       
     """
-    scalar = kwargs.pop('scalar', False)
-    if scalar:
+    if 'scalar' in kwargs:
         util.warn_deprecated('scalar option is deprecated; see docs for details')
+    scalar = kwargs.pop('scalar', False)
     s = Select(columns, whereclause=whereclause, from_obj=from_obj, **kwargs)
     if scalar:
         return s.as_scalar()