Table 'media' has 1 : N relationship to table 'history'.
class Media(object):
def addHistory(self, comment):
self.history.append(History(....)))
Inside addHistory() I need to get hold of the mapper class History for
'history' in order to append a new items to the media's history.
Unfortunately the complete mappers are hidden behind a wrapper and the
mappers are only available to the application through a dedicated
getMapper() call returning a registered mapper by name. However the wrapper
instance
is not available to the Media mapper itself. Is there a way to get hold
of depending mapper classes - in this case the History mapper - directly
from the Media mapper class (since it knows that it depends on the History
mapper)?
Andreas
> I have the following (scary) use-case:
>
> Table 'media' has 1 : N relationship to table 'history'.
>
> class Media(object):
>
> def addHistory(self, comment):
> self.history.append(History(....)))
>
>
> Inside addHistory() I need to get hold of the mapper class History
> for 'history' in order to append a new items to the media's history.
ok, you mean a "mapped" class, right ? i.e.the History class. i
dont exactly understand why you cant just say "History", so heres the
most generic way possible to go from 'self' to the class used on a
relation:
class_mapper(self.__class__).props['history'].mapper.class_
--On 12. Mai 2007 11:22:51 -0400 Michael Bayer <mik...@zzzcomputing.com>
wrote:
> ok, you mean a "mapped" class, right ? i.e.the History class. i
> dont exactly understand why you cant just say "History", so heres the
> most generic way possible to go from 'self' to the class used on a
> relation:
Basically this is a limitation (or call it a feature) of z3c.sqlalchemy
where the complete mapper handling is handled through a wrapper which isn't
available in the context of a mapper instance (unless you pass the wrapper
around).
>
> class_mapper(self.__class__).props['history'].mapper.class_
Thanks this works!
Andreas
>
>
>
>
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group. To post to this group, send email to
> sqlal...@googlegroups.com
> To unsubscribe from this group, send email to
> sqlalchemy-...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/sqlalchemy?hl=en
> -~----------~----~----~----~------~----~------~--~---
--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: in...@zopyx.com - Phone +49 - 7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535
Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK
------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting