Commits

Mike Bayer committed f40d328

- the SqlSoup constructor accepts a `base` argument which specifies
the base class to use for mapped classes, the default being
`object`. [ticket:1783]

Comments (0)

Files changed (3)

   - Added integer coercion to the "type_conv" attribute when 
     passed via query string, so that it is properly interpreted
     by Kinterbasdb. [ticket:1779]
-    
+
+- sqlsoup
+  - the SqlSoup constructor accepts a `base` argument which specifies
+    the base class to use for mapped classes, the default being
+    `object`.  [ticket:1783]
+
 0.6.0
 =====
 

lib/sqlalchemy/ext/sqlsoup.py

             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
     # 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())
     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
             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

test/ext/test_sqlsoup.py

         db = sqlsoup.SqlSoup(engine)
         tablename = 'loans'
         eq_(db.entity(tablename), db.loans)
+
+    def test_entity_with_different_base(self):
+        class subclass(object):
+            pass
+        db = sqlsoup.SqlSoup(engine, base=subclass)
+        assert issubclass(db.entity('loans'), subclass)
         
     def test_filter_by_order_by(self):
         db = sqlsoup.SqlSoup(engine)
 delete from books;
 delete from users;
 delete from nopk;
-""".split(";")
+""".split(";")