>
> Using the association_proxy extension in combination with your
> dictionary collection class is an easy way to get this kind of
> simplified access. Assuming your Attribute's value is in a
> property called 'value', you can set up simple dict access like so:
>
> class Obj(object):
> attrs = association_proxy('_attrs', 'value')
>
> mapper(Obj, ..., properties = {
> '_attrs': relation(Attribute, collection_class=your_dict_class)
> }
>
> obj.attrs['foo'] = 'a'
>
> -jek
When I try the above I get this error at flush time:
InvalidRequestError: Class 'str' entity name 'None' has no mapper
associated with it
Here is my dictionary collection_class:
class AttributeDictNEW(dict):
"""
My Attribute Dict
"""
def append(self, item):
super(AttributeDictNEW, self).__setitem__(item.name, item)
def test__iter__(self):
return iter(self.values())
def test__getitem__(self, name):
return super(AttributeDictNEW, self).__getitem__(name).value
def __setitem__(self, name, value):
if not isinstance(value, Attribute):
newattr = Attribute(name, str(value))
self.append(newattr)
else:
self.append(value)
The test__ functions are named such to get out of the way of the
parent class's functions while testing.
I may be misunderstanding how an association_proxy works.
-Ron
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---