diff options
author | jeff <none@none> | 2006-03-03 14:46:39 +0000 |
---|---|---|
committer | jeff <none@none> | 2006-03-03 14:46:39 +0000 |
commit | b87921caf32e285a1c6069b60da784358c61d6ae (patch) | |
tree | 80b9c74669a7341251b07edb77641e7ee75155ba /lib/sqlalchemy/ext/activemapper.py | |
parent | 13710ae742c18eb589a204bc9d242cccf66ae4b0 (diff) | |
download | sqlalchemy-b87921caf32e285a1c6069b60da784358c61d6ae.tar.gz |
rudimentary support for many-to-many relation. Still requires a separately defined intermediate table.
Diffstat (limited to 'lib/sqlalchemy/ext/activemapper.py')
-rw-r--r-- | lib/sqlalchemy/ext/activemapper.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/sqlalchemy/ext/activemapper.py b/lib/sqlalchemy/ext/activemapper.py index e5b3e4929..fdb796db2 100644 --- a/lib/sqlalchemy/ext/activemapper.py +++ b/lib/sqlalchemy/ext/activemapper.py @@ -25,8 +25,8 @@ class column(object): self.colname = colname self.foreign_key = foreign_key self.primary_key = primary_key - self.unique = kwargs.pop( 'unique', False ) - self.indexed = kwargs.pop( 'indexed', self.unique ) +# self.unique = kwargs.pop( 'unique', None ) +# self.index = kwargs.pop( 'indexed', None ) self.kwargs = kwargs self.args = args @@ -34,14 +34,15 @@ class column(object): # declarative relationship declaration # class relationship(object): - def __init__(self, classname, colname=None, backref=None, private=False, lazy=True, uselist=True): + def __init__(self, classname, colname=None, backref=None, private=False, + lazy=True, uselist=True, secondary=None): self.classname = classname self.colname = colname self.backref = backref self.private = private self.lazy = lazy self.uselist = uselist - + self.secondary = secondary class one_to_many(relationship): def __init__(self, classname, colname=None, backref=None, private=False, lazy=True): @@ -52,6 +53,10 @@ class one_to_one(relationship): def __init__(self, classname, colname=None, backref=None, private=False, lazy=True): relationship.__init__(self, classname, colname, backref, private, lazy, uselist=False) +class many_to_many(relationship): + def __init__(self, classname, secondary, backref=None, lazy=True): + relationship.__init__(self, classname, None, backref, False, lazy, + uselist=True, secondary=secondary) # @@ -73,7 +78,8 @@ def process_relationships(klass, was_deferred=False): relations = {} for propname, reldesc in klass.relations.items(): relclass = ActiveMapperMeta.classes[reldesc.classname] - relations[propname] = relation(relclass, + relations[propname] = relation(relclass.mapper, + secondary=reldesc.secondary, backref=reldesc.backref, private=reldesc.private, lazy=reldesc.lazy, @@ -122,10 +128,10 @@ class ActiveMapperMeta(type): primary_key=value.primary_key, *value.args, **value.kwargs) columns.append(col) - if value.indexed: - # create a Index object for the column - index= Index( "%s_idx" % (value.colname or name), - col, unique= value.unique ) +# if value.indexed: +# # create a Index object for the column +# index= Index( "%s_idx" % (value.colname or name), +# col, unique= value.unique ) continue if isinstance(value, relationship): @@ -155,4 +161,5 @@ class ActiveMapper(object): def create_tables(): for klass in ActiveMapperMeta.classes.values(): - klass.table.create()
\ No newline at end of file + klass.table.create() + |