예제 #1
0
 def _default_getset(self, collection_class):
     attr = self.value_attr
     getter = util.attrgetter(attr)
     if collection_class is dict:
         setter = lambda o, k, v: setattr(o, attr, v)
     else:
         setter = lambda o, v: setattr(o, attr, v)
     return getter, setter
예제 #2
0
def attribute_mapped_collection(attr_name):
    """A dictionary-based collection type with attribute-based keying.

    Returns a MappedCollection factory with a keying based on the
    'attr_name' attribute of entities in the collection.

    The key value must be immutable for the lifetime of the object.  You
    can not, for example, map on foreign key values if those key values will
    change during the session, i.e. from None to a database-assigned integer
    after a session flush.
    """

    return lambda: MappedCollection(attrgetter(attr_name))
예제 #3
0
def attribute_mapped_collection(attr_name):
    """A dictionary-based collection type with attribute-based keying.

    Returns a MappedCollection factory with a keying based on the
    'attr_name' attribute of entities in the collection.

    The key value must be immutable for the lifetime of the object.  You
    can not, for example, map on foreign key values if those key values will
    change during the session, i.e. from None to a database-assigned integer
    after a session flush.
    """

    return lambda: MappedCollection(attrgetter(attr_name))