summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/mutable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-04-02 16:00:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-04-02 16:00:35 -0400
commit301438235ecf8359a278e87b26d264d2e91b9702 (patch)
tree7e4584760c570d0dcb194370c65202505d69b7aa /lib/sqlalchemy/ext/mutable.py
parent0b52a5ae744acad5c58f382049ecdbd954fc7ee6 (diff)
downloadsqlalchemy-301438235ecf8359a278e87b26d264d2e91b9702.tar.gz
- Fixed mutable extension docs to show the
correct type-association methods. [ticket:2118]
Diffstat (limited to 'lib/sqlalchemy/ext/mutable.py')
-rw-r--r--lib/sqlalchemy/ext/mutable.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py
index c3bb2b9f7..9be559d04 100644
--- a/lib/sqlalchemy/ext/mutable.py
+++ b/lib/sqlalchemy/ext/mutable.py
@@ -101,20 +101,20 @@ applied to a parent object which are not instances of the mutable type
will raise a ``ValueError``.
Our new ``MutationDict`` type offers a class method
-:meth:`~.Mutable.associate_with` which we can use within column metadata
-to associate with types. This method grabs the given type object and
-associates a listener that will detect all future mappings of this type,
-applying event listening instrumentation to the mapped attribute. Such as,
-with classical table metadata::
+:meth:`~.Mutable.as_mutable` which we can use within column metadata
+to associate with types. This method grabs the given type object or
+class and associates a listener that will detect all future mappings
+of this type, applying event listening instrumentation to the mapped
+attribute. Such as, with classical table metadata::
from sqlalchemy import Table, Column, Integer
-
+
my_data = Table('my_data', metadata,
Column('id', Integer, primary_key=True),
- Column('data', MutationDict.associate_with(JSONEncodedDict))
+ Column('data', MutationDict.as_mutable(JSONEncodedDict))
)
-Above, :meth:`~.Mutable.associate_with` returns an instance of ``JSONEncodedDict``
+Above, :meth:`~.Mutable.as_mutable` returns an instance of ``JSONEncodedDict``
(if the type object was not an instance already), which will intercept any
attributes which are mapped against this type. Below we establish a simple
mapping against the ``my_data`` table::
@@ -139,7 +139,7 @@ There's no difference in usage when using declarative::
class MyDataClass(Base):
__tablename__ = 'my_data'
id = Column(Integer, primary_key=True)
- data = Column(MutationDict.associate_with(JSONEncodedDict))
+ data = Column(MutationDict.as_mutable(JSONEncodedDict))
Any in-place changes to the ``MyDataClass.data`` member
will flag the attribute as "dirty" on the parent object::
@@ -155,6 +155,20 @@ will flag the attribute as "dirty" on the parent object::
>>> assert m1 in sess.dirty
True
+The ``MutationDict`` can be associated with all future instances
+of ``JSONEncodedDict`` in one step, using :meth:`~.Mutable.associate_with`. This
+is similar to :meth:`~.Mutable.as_mutable` except it will intercept
+all occurrences of ``MutationDict`` in all mappings unconditionally, without
+the need to declare it individually::
+
+ MutationDict.associate_with(JSONEncodedDict)
+
+ class MyDataClass(Base):
+ __tablename__ = 'my_data'
+ id = Column(Integer, primary_key=True)
+ data = Column(JSONEncodedDict)
+
+
Supporting Pickling
--------------------
@@ -468,7 +482,7 @@ class Mutable(MutableBase):
To associate a particular mutable type with all occurrences of a
particular type, use the :meth:`.Mutable.associate_with` classmethod
of the particular :meth:`.Mutable` subclass to establish a global
- assoiation.
+ association.
.. warning:: The listeners established by this method are *global*
to all mappers, and are *not* garbage collected. Only use
@@ -524,7 +538,7 @@ class MutableComposite(MutableBase):
@classmethod
def _setup_listeners(cls):
- """Associate this wrapper with all future mapped compoistes
+ """Associate this wrapper with all future mapped composites
of the given type.
This is a convenience method that calls ``associate_with_attribute`` automatically.