-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 13.01.2009 15:52 Uhr, Michael Bayer wrote: > > On Jan 13, 2009, at 8:19 AM, Andreas Jung wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Is it possible to define multiple mappers for one table? >> >> Usecase: I have one big table (60 cols) and one big mapper class. >> For some reporting I don't need only a small number of cols. For >> performance reasons I would like to load the related rows using a very >> minimal mapper. However there is no obvious way to configure a >> non-primary mapper using the declarative layer? > > declarative can't create non primary mappers (it would be a > contradiction), but "non primary mapper" only applies to multiple > mappers for a class, not for a table. any number of mappers of any > kind can point to a single table. > > to map to any table just set the __table__ argument to the Table. if > you already have another declarative class, youd say __table__ = > MyOtherClass.__table__. > >
This fails: This is full-fledged mapper: class Arbeitsmittel(Base, AsDictMixin): __tablename__ = 'arbeitsmittel' __table_args__ = ( { 'autoload' : True, }) # column redefinitions needed for relation()s below idfassung = Column(Integer, ForeignKey('fassung.id')) format = Column(String, ForeignKey('format.format')) status = Column(Integer, ForeignKey('status.id')) idsachgebiet = Column(Integer, ForeignKey('sachgebiet.id')) idzielgruppe = Column(Integer, ForeignKey('zielgruppen.id')) idgattung = Column(Integer, ForeignKey('gattung.id')) styleguide_compliant = Column(Integer, ForeignKey('styleguide_compliant.id')) The minimal mapper looks like this: class ArbeitsmittelMinimal(Base, AsDictMixin): __table__ = Arbeitsmittel.__table__ hidx = Column(String, primary_key=True) /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/engine/base.py:1265: SAWarning: Predicate of partial index hierarchies_pid_is_root_true ignored during reflection self.dialect.reflecttable(conn, table, include_columns) 2009-01-13 16:03:47 ERROR Zope Couldn't install Toolbox Traceback (innermost last): Module OFS.Application, line 806, in install_product - __traceback_info__: Toolbox Module Products.Toolbox, line 20, in initialize Module toolbox.database.setup, line 74, in setup Module z3c.sqlalchemy.util, line 70, in createSAWrapper Module z3c.sqlalchemy.base, line 81, in __init__ Module toolbox.database.model, line 791, in getModel Module toolbox.database.model, line 779, in modelAll Module sqlalchemy.ext.declarative, line 372, in __init__ Module sqlalchemy.ext.declarative, line 364, in _as_declarative Module sqlalchemy.orm, line 736, in mapper Module sqlalchemy.orm.mapper, line 196, in __init__ Module sqlalchemy.orm.mapper, line 481, in _configure_properties Module sqlalchemy.orm.mapper, line 578, in _compile_property Module sqlalchemy.schema, line 618, in __str__ Module sqlalchemy.util, line 1358, in __get__ Module sqlalchemy.sql.expression, line 2805, in description AttributeError: 'NoneType' object has no attribute 'encode' Traceback (most recent call last): File "<string>", line 1, in ? File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/Zope2/__init__.py", line 55, in app startup() File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/Zope2/__init__.py", line 51, in startup _startup() File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/Zope2/App/startup.py", line 138, in startup OFS.Application.initialize(application) File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/OFS/Application.py", line 303, in initialize initializer.initialize() File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/OFS/Application.py", line 332, in initialize self.install_products() File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/OFS/Application.py", line 612, in install_products return install_products(app) File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/OFS/Application.py", line 647, in install_products raise_exc=raise_on_error, File "/local/HRS2/Devel/junga/tb-dev/parts/zope2/lib/python/OFS/Application.py", line 806, in install_product initmethod(context) File "/local/HRS2/Devel/junga/tb-dev/parts/products-svn/Toolbox/__init__.py", line 20, in initialize setup(forZope=True, echo=echo) File "/local/HRS2/Devel/junga/tb-dev/parts/modules-svn/toolbox/database/setup.py", line 74, in setup name=TOOLBOX_WRAPPER_NAME) File "/local/HRS2/Devel/junga/tb-dev/eggs/z3c.sqlalchemy-1.3.9-py2.4.egg/z3c/sqlalchemy/util.py", line 70, in createSAWrapper extension_options=extension_options, File "/local/HRS2/Devel/junga/tb-dev/eggs/z3c.sqlalchemy-1.3.9-py2.4.egg/z3c/sqlalchemy/base.py", line 81, in __init__ self._model = model(self.metadata) File "/local/HRS2/Devel/junga/tb-dev/parts/modules-svn/toolbox/database/model.py", line 791, in getModel modelAll(Base, model) File "/local/HRS2/Devel/junga/tb-dev/parts/modules-svn/toolbox/database/model.py", line 779, in modelAll class ArbeitsmittelMinimal(Base, AsDictMixin): File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/ext/declarative.py", line 372, in __init__ _as_declarative(cls, classname, dict_) File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/ext/declarative.py", line 364, in _as_declarative cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff, File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/orm/__init__.py", line 736, in mapper return Mapper(class_, local_table, *args, **params) File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/orm/mapper.py", line 196, in __init__ self._configure_properties() File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/orm/mapper.py", line 481, in _configure_properties self._compile_property(key, prop, False) File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/orm/mapper.py", line 578, in _compile_property raise sa_exc.ArgumentError("Column '%s' is not represented in mapper's table. " File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/schema.py", line 618, in __str__ return self.description File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/util.py", line 1358, in __get__ obj.__dict__[self.__name__] = result = self.fget(obj) File "/local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.0-py2.4.egg/sqlalchemy/sql/expression.py", line 2805, in description return self.name.encode('ascii', 'backslashreplace') AttributeError: 'NoneType' object has no attribute 'encode' -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAklsrXAACgkQCJIWIbr9KYwypgCgqo0dqNFvjOEUiBStsb5dFzOm LA4An2+ji3m2GWkgW7FDFM1CO1C8Wp3I =Pk/r -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. & Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany email;internet:i...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard