diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-05-08 15:08:48 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-05-08 15:08:48 -0400 |
commit | 0934e217f82f11873d12dd7b4d1a3e2c336682c7 (patch) | |
tree | 979b345e7479aaa63c484f6c5b6e0797c3c39703 /lib/sqlalchemy/ext/sqlsoup.py | |
parent | d997bbaea827f5a14089ae42b5bd5d5e77589fd8 (diff) | |
download | sqlalchemy-0934e217f82f11873d12dd7b4d1a3e2c336682c7.tar.gz |
- the SqlSoup constructor accepts a `base` argument which specifies
the base class to use for mapped classes, the default being
`object`. [ticket:1783]
Diffstat (limited to 'lib/sqlalchemy/ext/sqlsoup.py')
-rw-r--r-- | lib/sqlalchemy/ext/sqlsoup.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index 4d5f4b76f..e54cde3ed 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -395,7 +395,7 @@ def _selectable_name(selectable): x = x[1:] return x -def _class_for_table(session, engine, selectable, **mapper_kwargs): +def _class_for_table(session, engine, selectable, base_cls=object, **mapper_kwargs): selectable = expression._clause_element_as_expr(selectable) mapname = 'Mapped' + _selectable_name(selectable) # Py2K @@ -405,9 +405,9 @@ def _class_for_table(session, engine, selectable, **mapper_kwargs): # end Py2K if isinstance(selectable, Table): - klass = TableClassType(mapname, (object,), {}) + klass = TableClassType(mapname, (base_cls,), {}) else: - klass = SelectableClassType(mapname, (object,), {}) + klass = SelectableClassType(mapname, (base_cls,), {}) def _compare(self, o): L = list(self.__class__.c.keys()) @@ -451,14 +451,17 @@ def _class_for_table(session, engine, selectable, **mapper_kwargs): return klass class SqlSoup(object): - def __init__(self, engine_or_metadata, **kw): + def __init__(self, engine_or_metadata, base=object, **kw): """Initialize a new ``SqlSoup``. + `base` is the class that all created entity classes should subclass. + `args` may either be an ``SQLEngine`` or a set of arguments suitable for passing to ``create_engine``. """ self.session = kw.pop('session', Session) + self.base=base if isinstance(engine_or_metadata, MetaData): self._metadata = engine_or_metadata @@ -537,7 +540,7 @@ class SqlSoup(object): if not table.primary_key.columns: raise PKNotFoundError('table %r does not have a primary key defined [columns: %s]' % (attr, ','.join(table.c.keys()))) if table.columns: - t = _class_for_table(self.session, self.engine, table) + t = _class_for_table(self.session, self.engine, table, self.base) else: t = None self._cache[attr] = t |