Ach, I did it again... proceeded as if column_mapped_collection and attribute_mapped_collection provide collection classes that are dicts of lists. No, they're just dicts of scalar values!
Again and again I need dicts of lists. They seem to really fit the data that I tend to work with; A's related to C's indexed by B's (the B typically indicating the *type* of relationship between the A and the C). Eventually I need to work my own implementation of dict-of-lists and dict-of-dicts collection classes up to full strength so I can share them as a recipe or extension or something. On Mar 10, 1:02 pm, Eric Ongerth <ericonge...@gmail.com> wrote: > I make occasional use of alternate collection classes for my > sqlalchemy relationships. For example, column_mapped_collection. The > existing collection classes in sqlalchemy.orm.collections work really > well for me; I have a lot of relational data that very naturally > belongs in dicts rather than lists because it makes sense as one thing > indexed or mapped by another. > > I find that I often need to add an item to one of these dict-mapped > collections and would rather not have to check whether the key already > exists in the dict. So I'm doing, essentially: > collection.setdefault(key, []).append(value). > > As a matter of syntactic sugar (which alternative collection classes > already are, anyway) I would like to have collection classes backed by > dicts with the capability of python's defaultdict, so that I could > write more simply, and with equivalent results: > collection[key].append(value) > > I understand how to create my own collection class which will behave > as desired. My question is, has anyone already got code for this that > I could borrow rather than reinvent the wheel? Thanks in advance. -- > Eric -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.