diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-08 19:56:45 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-08 19:56:45 -0400 |
| commit | d47ec4158dd75cfd254db60002f797cfc24502fa (patch) | |
| tree | c6553cdb6b707355645d99bb19e62ac2f4310e4f | |
| parent | a1d9c824dae8e6b1819e9a636cef387ee9e30576 (diff) | |
| parent | 99713acd79b0cbaebb0d09050e5c6c2fba05b3eb (diff) | |
| download | sqlalchemy-d47ec4158dd75cfd254db60002f797cfc24502fa.tar.gz | |
fixes, but still unsure of things
| -rw-r--r-- | doc/build/reference/sqlalchemy/event.rst | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/event.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 24 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/interfaces.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/util.py | 5 |
5 files changed, 38 insertions, 10 deletions
diff --git a/doc/build/reference/sqlalchemy/event.rst b/doc/build/reference/sqlalchemy/event.rst new file mode 100644 index 000000000..05e7ab63b --- /dev/null +++ b/doc/build/reference/sqlalchemy/event.rst @@ -0,0 +1,7 @@ +Events +------ + +.. automodule:: sqlalchemy.event + :members: + + diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index 73be57b55..f9fbcc118 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -146,6 +146,9 @@ class Listeners(_ExecEvent): return bool(self.listeners or self.parent_listeners) def append(self, obj, target): + # this will be needed, but not + # sure why we don't seem to need it yet + # if obj not in self.listeners: self.listeners.append(obj) class dispatcher(object): diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 76a89a0d0..9d454a7b2 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -104,9 +104,6 @@ class QueryableAttribute(interfaces.PropComparator): self.comparator = comparator self.parententity = parententity - # TODO: this can potentially be moved to AttributeImpl, - # have Sphinx document the "events" class directly, implement an - # accept_with() that checks for QueryableAttribute class events(event.Events): """Events for ORM attributes. @@ -123,6 +120,12 @@ class QueryableAttribute(interfaces.PropComparator): active_history = False + # TODO: what to do about subclasses !! + # a shared approach will be needed. listeners can be placed + # before subclasses are created. new attrs on subclasses + # can pull them from the superclass attr. listeners + # should be auto-propagated to existing subclasses. + @classmethod def listen(cls, fn, identifier, target, active_history=False): if active_history: @@ -347,7 +350,10 @@ class AttributeImpl(object): else: self.is_equal = compare_function - attr = getattr(class_, key) + # TODO: pass in the manager here + # instead of doing a lookup + attr = manager_of_class(class_)[key] + for ext in util.to_list(extension or []): ext._adapt_listener(attr, ext) @@ -356,7 +362,6 @@ class AttributeImpl(object): self.expire_missing = expire_missing - def hasparent(self, state, optimistic=False): """Return the boolean value of a `hasparent` flag attached to the given state. @@ -1011,6 +1016,14 @@ class ClassManager(dict): def mapper(self): raise exc.UnmappedClassError(self.class_) + def _attr_has_impl(self, key): + """Return True if the given attribute is fully initialized. + + i.e. has an impl. + """ + + return key in self and self[key].impl is not None + def _configure_create_arguments(self, _source=None, deferred_scalar_loader=None): @@ -1504,6 +1517,7 @@ def register_attribute_impl(class_, key, manager[key].impl = impl manager.post_configure_attribute(key) + def register_descriptor(class_, key, proxy_property=None, comparator=None, parententity=None, property_=None, doc=None): diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 945b657e4..77a387f84 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -482,7 +482,7 @@ class MapperProperty(object): _compile_started = False _compile_finished = False - + def init(self): """Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation @@ -647,7 +647,7 @@ class StrategizedProperty(MapperProperty): ``StrategizedOption`` objects via the Query.options() method. """ - + def _get_context_strategy(self, context, path): cls = context.attributes.get(('loaderstrategy', _reduce_path(path)), None) @@ -683,9 +683,10 @@ class StrategizedProperty(MapperProperty): self.strategy = self.__init_strategy(self.strategy_class) def post_instrument_class(self, mapper): - if self.is_primary(): + if self.is_primary() and \ + not mapper.class_manager._attr_has_impl(self.key): self.strategy.init_class_attribute(mapper) - + def build_path(entity, key, prev=None): if prev: return prev + (entity, key) diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index d274e3635..c26f38b6b 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -907,7 +907,10 @@ class OrderedSet(set): def __iter__(self): return iter(self._list) - + + def __add__(self, other): + return self.union(other) + def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self._list) |
