Ron wrote:
> 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.
The association proxy will take care of Attribute construction for
you, so you can get away with just:
class AttributeDictNEW(dict):
def append(self, item):
self[item.key] = item
def __iter__(self):
return self.itervalues()
However,
>
> newattr = Attribute(name, str(value))
>
For the stringification of values on construction, you can either
do that in Attribute's __init__ or supply a creator function to the
association proxy:
stringy_attr = lambda name, value: Attribute(name, str(value))
...
attrs = association_proxy('_attrs', 'value', creator=stringy_attr)
-jek
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---