diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-25 13:22:12 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-25 13:22:12 -0500 |
| commit | 9c7b00455954239dd2f8f9813fb1c024f4202ebf (patch) | |
| tree | 0fc70611b00cf4f40c1d7c736d442a7d014dcba6 /lib/sqlalchemy | |
| parent | 5291df27000d5da8693c1278de557d01ffca046b (diff) | |
| download | sqlalchemy-9c7b00455954239dd2f8f9813fb1c024f4202ebf.tar.gz | |
- add a new "on mapper configured" event - handy !
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/events.py | 29 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 1 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index f511b0e40..48b559c63 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -267,8 +267,11 @@ class MapperEvents(event.Events): event.Events.listen(target, identifier, fn) def on_instrument_class(self, mapper, class_): - """Receive a class when the mapper is first constructed, and has - applied instrumentation to the mapped class. + """Receive a class when the mapper is first constructed, + before instrumentation is applied to the mapped class. + + This event is the earliest phase of mapper construction. + Most attributes of the mapper are not yet initialized. This listener can generally only be applied to the :class:`.Mapper` class overall. @@ -278,7 +281,20 @@ class MapperEvents(event.Events): :param class\_: the mapped class. """ + + def on_mapper_configured(self, mapper, class_): + """Called when the mapper for the class is fully configured. + This event is the latest phase of mapper construction. + The mapper should be in its final state. + + :param mapper: the :class:`.Mapper` which is the target + of this event. + :param class\_: the mapped class. + + """ + # TODO: need coverage for this event + def on_translate_row(self, mapper, context, row): """Perform pre-processing on the given result row and return a new row instance. @@ -818,6 +834,15 @@ class AttributeEvents(event.Events): or "append" event. """ + + @classmethod + def accept_with(cls, target): + from sqlalchemy.orm import interfaces + # TODO: coverage + if isinstance(target, interfaces.MapperProperty): + return getattr(target.parent.class_, target.key) + else: + return target @classmethod def listen(cls, target, identifier, fn, active_history=False, diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index f2bc04570..e9271008e 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -2401,6 +2401,7 @@ def configure_mappers(): try: mapper._post_configure_properties() mapper._expire_memoizations() + mapper.dispatch.on_mapper_configured(mapper, mapper.class_) except: exc = sys.exc_info()[1] if not hasattr(exc, '_configure_failed'): |
