diff options
author | Gaëtan de Menten <gdementen@gmail.com> | 2007-07-31 14:54:28 +0000 |
---|---|---|
committer | Gaëtan de Menten <gdementen@gmail.com> | 2007-07-31 14:54:28 +0000 |
commit | 9c31abf1d3bc06b6e7eba8d4bbee7569636c4a33 (patch) | |
tree | d83497ae5277e18079ca94a71c1ead2fee673698 /lib/sqlalchemy/ext/assignmapper.py | |
parent | 04e8a839b4bc6a612b88ff793755865591b48ac4 (diff) | |
download | sqlalchemy-9c31abf1d3bc06b6e7eba8d4bbee7569636c4a33.tar.gz |
- restored old assign_mapper monkey patched query methods but with two differences:
* added a deprecation warning
* check if a method with that name already exist in the class
- more foolproof deprecation warning for scalar kwarg
Diffstat (limited to 'lib/sqlalchemy/ext/assignmapper.py')
-rw-r--r-- | lib/sqlalchemy/ext/assignmapper.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py index 238041702..cab5a9eae 100644 --- a/lib/sqlalchemy/ext/assignmapper.py +++ b/lib/sqlalchemy/ext/assignmapper.py @@ -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) |