]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added the :paramref:`.AssociationProxy.info` parameter to the
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Oct 2015 22:01:43 +0000 (18:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Oct 2015 22:01:43 +0000 (18:01 -0400)
:class:`.AssociationProxy` constructor, to suit the
:attr:`.AssociationProxy.info` accessor that was added in
:ticket:`2971`.  This is possible because :class:`.AssociationProxy`
is constructed explicitly, unlike a hybrid which is constructed
implicitly via the decorator syntax.
fixes #3551

doc/build/changelog/changelog_10.rst
doc/build/orm/extensions/associationproxy.rst
lib/sqlalchemy/ext/associationproxy.py
test/ext/test_associationproxy.py

index a3b3e0092ca00457accc02dcf4a514665ef1e762..b6a944a1e91f43b3c689199e0339d92d6742a594 100644 (file)
 .. changelog::
     :version: 1.0.9
 
+    .. change::
+        :tags: feature, ext
+        :versions: 1.1.0b1
+        :tickets: 3551
+
+        Added the :paramref:`.AssociationProxy.info` parameter to the
+        :class:`.AssociationProxy` constructor, to suit the
+        :attr:`.AssociationProxy.info` accessor that was added in
+        :ticket:`2971`.  This is possible because :class:`.AssociationProxy`
+        is constructed explicitly, unlike a hybrid which is constructed
+        implicitly via the decorator syntax.
+
     .. change::
         :tags: bug, oracle
         :versions: 1.1.0b1
index 6fc57e30cc97fd04f7cc8a4635f444c030e250aa..7e7b1f9de49bdd328783625cae89cc31197c5818 100644 (file)
@@ -509,5 +509,6 @@ API Documentation
 .. autoclass:: AssociationProxy
    :members:
    :undoc-members:
+   :inherited-members:
 
 .. autodata:: ASSOCIATION_PROXY
index d837aab520abc71b177ffe0d9c8c06e9016421ab..29064ef27b2b84421a3f6e7b1626fb66938e07f9 100644 (file)
@@ -94,7 +94,7 @@ class AssociationProxy(interfaces.InspectionAttrInfo):
 
     def __init__(self, target_collection, attr, creator=None,
                  getset_factory=None, proxy_factory=None,
-                 proxy_bulk_set=None):
+                 proxy_bulk_set=None, info=None):
         """Construct a new :class:`.AssociationProxy`.
 
         The :func:`.association_proxy` function is provided as the usual
@@ -138,6 +138,11 @@ class AssociationProxy(interfaces.InspectionAttrInfo):
         :param proxy_bulk_set: Optional, use with proxy_factory.  See
           the _set() method for details.
 
+        :param info: optional, will be assigned to
+         :attr:`.AssociationProxy.info` if present.
+
+         .. versionadded:: 1.0.9
+
         """
         self.target_collection = target_collection
         self.value_attr = attr
@@ -150,6 +155,8 @@ class AssociationProxy(interfaces.InspectionAttrInfo):
         self.key = '_%s_%s_%s' % (
             type(self).__name__, target_collection, id(self))
         self.collection_class = None
+        if info:
+            self.info = info
 
     @property
     def remote_attr(self):
index 8fb335b064b02c9a05072a2633e44f1543a0aa93..98e40b11ee6e23874e709a514594c09ee7e8ef82 100644 (file)
@@ -1593,3 +1593,23 @@ class DictOfTupleUpdateTest(fixtures.TestBase):
             a1.elements.update,
             (("B", 3), 'elem2'), (("C", 4), "elem3")
         )
+
+
+class InfoTest(fixtures.TestBase):
+    def test_constructor(self):
+        assoc = association_proxy('a', 'b', info={'some_assoc': 'some_value'})
+        eq_(assoc.info, {"some_assoc": "some_value"})
+
+    def test_empty(self):
+        assoc = association_proxy('a', 'b')
+        eq_(assoc.info, {})
+
+    def test_via_cls(self):
+        class Foob(object):
+            assoc = association_proxy('a', 'b')
+
+        eq_(Foob.assoc.info, {})
+
+        Foob.assoc.info["foo"] = 'bar'
+
+        eq_(Foob.assoc.info, {'foo': 'bar'})