- attached sqlsoup.patch
add optional base parameter to SqlSoup.entity to override a base class for mapped objects
this is useful when you want to create some helper functions/properties.
discussed on http://bit.ly/c77Dt2
here's the final patch:
==================== --- sqlsoup.py.old 2010-11-17 22:41:14.212129086 +0000 +++ sqlsoup.py 2010-11-18 01:50:13.443881826 +0000 @@ -540,7 +540,8 @@ j = join(args, *kwargs) return self.map(j) - def entity(self, attr, schema=None): + def entity(self, attr, schema=None, base=None): + if base and attr in self._cache: del self._cacheattr try: t = self._cacheattr except KeyError, ke: @@ -548,7 +549,7 @@ if not table.primary_key.columns: raise PKNotFoundError('table %r does not have a primary key def ined %s' % (attr, ','.join(table.c.keys()))) if table.columns: - t = _class_for_table(self.session, self.engine, table, self.base) + t = _class_for_table(self.session, self.engine, table, base or self.base) else: t = None self._cacheattr = t ====================
Comments (5)
-
Account Deleted -
Account Deleted attached the patch file since this wiki thing formatted things horribly...
-
repo owner as I've mentioned in email, I don't like this solution at all. its fragile and inelegant. So far I'm still of the opinion that SqlSoup is not intended for ad-hoc creation of real domain models and you should be using declarative instead. What's the reason for not doing so ?
-
repo owner - changed watchers to jin@recessnetworks.net
- changed milestone to 0.6.6
- changed status to resolved
a new method
map_to()
has been added toSqlSoup
in c848624f9db325213ddf2fde9819946f9eb235cd. This is a method that you can call ahead of time, given a particularSqlSoup
attribute name, to map that name to a class/table/selectable in a specific way. Subsequent calls to that name via regular__getattr__()
access will return that mapped class. The method is strict and can only be called once for a particular name, and only for names that do not exist already, meaning you're going to want to call a series ofmap_to()
calls right when you generate yourSqlSoup
object:db = SqlSoup('mysql://...') db.map_to('users', tablename='users', base=MyUserBase) db.map_to('addresses', tablename='addresses', base=MyAddressBase) # use normally for user in db.users.all(): print user
-
repo owner - removed milestone
Removing milestone: 0.6.6 (automated comment)
- Log in to comment
specified patch