0.7.6
=====
- orm
+ - [bug] Fixed bug whereby MappedCollection
+ would not get the appropriate collection
+ instrumentation if it were only used
+ in a custom subclass that used
+ @collection.internally_instrumented.
+ [ticket:2406]
+
- [feature] Added the ability to query for
Table-bound column names when using
query(sometable).filter_by(colname=value).
Custom Collection Implementations
==================================
-You can use your own types for collections as well. In simple cases,
+You can use your own types for collections as well. In simple cases,
inherting from ``list`` or ``set``, adding custom behavior, is all that's needed.
In other cases, special decorators are needed to tell SQLAlchemy more detail
about how the collection operates.
methods in the basic dictionary interface for SQLAlchemy to use by default.
Iteration will go through ``itervalues()`` unless otherwise decorated.
+.. note::
+
+ Due to a bug in MappedCollection prior to version 0.7.6, this
+ workaround usually needs to be called before a custom subclass
+ of :class:`.MappedCollection` which uses :meth:`.collection.internally_instrumented`
+ can be used::
+
+ from sqlalchemy.orm.collections import _instrument_class, MappedCollection
+ _instrument_class(MappedCollection)
+
+ This will ensure that the :class:`.MappedCollection` has been properly
+ initialized with custom ``__setitem__()`` and ``__delitem__()``
+ methods before used in a custom subclass.
+
.. autoclass:: sqlalchemy.orm.collections.MappedCollection
:members:
.. autofunction:: bulk_replace
+.. autoclass:: collection
+
.. autofunction:: collection_adapter
.. autoclass:: CollectionAdapter
methods[name] = None, None, after
# apply ABC auto-decoration to methods that need it
+
for method, decorator in decorators.items():
fn = getattr(cls, method, None)
if (fn and method not in methods and
incoming_key, value, new_key))
yield value
_convert = collection.converter(_convert)
+
+# ensure instrumentation is associated with
+# these built-in classes; if a user-defined class
+# subclasses these and uses @internally_instrumented,
+# the superclass is otherwise not instrumented.
+# see [ticket:2406].
+_instrument_class(MappedCollection)
+_instrument_class(InstrumentedList)
+_instrument_class(InstrumentedSet)
+