summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/activemapper.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@cleverdevil.org>2006-06-28 17:26:48 +0000
committerJonathan LaCour <jonathan@cleverdevil.org>2006-06-28 17:26:48 +0000
commit70b2dec19a9d5f2dd163704e58f38f2f82e5bf45 (patch)
tree46c0296fa4e778ae5bdd09cb11e6e5fb23ee5f4f /lib/sqlalchemy/ext/activemapper.py
parent7626fc5aab8b625bb6e48e7374d4622efc7f1e5a (diff)
downloadsqlalchemy-70b2dec19a9d5f2dd163704e58f38f2f82e5bf45.tar.gz
Updated ActiveMapper to support order_by parameters on all relationships.
Thanks to Charles Duffy for this patch!
Diffstat (limited to 'lib/sqlalchemy/ext/activemapper.py')
-rw-r--r--lib/sqlalchemy/ext/activemapper.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/sqlalchemy/ext/activemapper.py b/lib/sqlalchemy/ext/activemapper.py
index a7be6ada9..22087e5ea 100644
--- a/lib/sqlalchemy/ext/activemapper.py
+++ b/lib/sqlalchemy/ext/activemapper.py
@@ -47,7 +47,7 @@ class column(object):
#
class relationship(object):
def __init__(self, classname, colname=None, backref=None, private=False,
- lazy=True, uselist=True, secondary=None):
+ lazy=True, uselist=True, secondary=None, order_by=False):
self.classname = classname
self.colname = colname
self.backref = backref
@@ -55,25 +55,28 @@ class relationship(object):
self.lazy = lazy
self.uselist = uselist
self.secondary = secondary
+ self.order_by = order_by
class one_to_many(relationship):
def __init__(self, classname, colname=None, backref=None, private=False,
- lazy=True):
+ lazy=True, order_by=False):
relationship.__init__(self, classname, colname, backref, private,
- lazy, uselist=True)
+ lazy, uselist=True, order_by=order_by)
class one_to_one(relationship):
def __init__(self, classname, colname=None, backref=None, private=False,
- lazy=True):
+ lazy=True, order_by=False):
if backref is not None:
backref = create_backref(backref, uselist=False)
relationship.__init__(self, classname, colname, backref, private,
- lazy, uselist=False)
+ lazy, uselist=False, order_by=order_by)
class many_to_many(relationship):
- def __init__(self, classname, secondary, backref=None, lazy=True):
+ def __init__(self, classname, secondary, backref=None, lazy=True,
+ order_by=False):
relationship.__init__(self, classname, None, backref, False, lazy,
- uselist=True, secondary=secondary)
+ uselist=True, secondary=secondary,
+ order_by=order_by)
#
@@ -125,12 +128,19 @@ def process_relationships(klass, was_deferred=False):
relations = {}
for propname, reldesc in klass.relations.items():
relclass = ActiveMapperMeta.classes[reldesc.classname]
+ if isinstance(reldesc.order_by, str):
+ reldesc.order_by = [ reldesc.order_by ]
+ if isinstance(reldesc.order_by, list):
+ for itemno in range(len(reldesc.order_by)):
+ if isinstance(reldesc.order_by[itemno], str):
+ reldesc.order_by[itemno] = getattr(relclass.c, reldesc.order_by[itemno])
relations[propname] = relation(relclass.mapper,
secondary=reldesc.secondary,
backref=reldesc.backref,
private=reldesc.private,
lazy=reldesc.lazy,
- uselist=reldesc.uselist)
+ uselist=reldesc.uselist,
+ order_by=reldesc.order_by)
class_mapper(klass).add_properties(relations)
if klass in __deferred_classes__: