It occurs to me that a near analogue to this would be... storing a
collection of one man's children by different mothers.  While it's
somewhat useful to have a collection of the guy's children... what if
you want to look up his children by just one mother, or by each mother
in turn.  There's an easy workaround, just looking up the list of his
children then asking each child whom its mother is.  But that's not
nearly as efficient as having his children collection indexed by
mother.  That's basically all I'm trying to do here (though totally
not the problem domain i'm working in!)

Thanks again.

On Feb 16, 2:23 pm, Eric Ongerth <[EMAIL PROTECTED]> wrote:
> Awesome -- Mike, that's a heck of a great response and I'll try it all
> out.
>
> But one quick reply to your very first comment, before I go out and do
> so.
>
> You wrote:
>
> <quote>
> Im not sure you're going to be able to use the collection classes
> here
> - those are all built on the notion of mapped elements being
> "appended" and "removed" from a collection.....but here you are
> appending and removing further subsets of elements.
> </quote>
>
> Actually, I don't need or want the ability to append or remove entire
> subsets.  There will only be a single element appended or removed at a
> time.  It's just that when a Bar is added to one of these "children"
> collections, I want it to be filed under a dict slot whose key happens
> to be the Bar's "parent" attribute.  It should join all the other
> elements stored in a list which holds the contents of that dict slot.
> Know what I mean?  Similarly, when I remove a Bar from one of these
> "children" collections, we look at its "parent" attribute to determine
> which slot in the collection it should be removed from, then it gets
> removed from the list which holds the contents of that dict slot.
> (Sorry, nonstandard use of the word "slot" here, just to avoid any
> ambiguity in using the word "value" to speak of what's on the right
> side of the colon in a dict entry).
>
> My guess is that making this clear, changes your idea of what I'm
> trying to achieve.  Let me know if that's the case.  If not, I need to
> read more deeply into what you wrote.  In either case I'm going to try
> out your examples.  Thanks a bundle for the length and quality of
> response.
>
> On Feb 16, 2:03 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> > yet another adjustment to ListAdapter...
>
> > class ListAdapter(object):
> >      def __init__(self, parent, key):
> >          self.__parent = parent
> >          self.__key = key
>
> >      def __cached(self):
> >          try:
> >              return self.__cached_data
> >          except AttributeError:
> >              self.__cached_data = [item.data for item in
> > self.__parent._data if item.key == self.__key]
> >              return self.__cached_data
> >      __cached = property(__cached)
>
> >      def __delcached(self):
> >          try:
> >              del self.__cached_data
> >          except AttributeError:
> >              pass
>
> >      def __iter__(self):
> >          return iter(self.__cached)
>
> >      def __eq__(self, other):
> >          return list(self) == list(other)
>
> >      def __repr__(self):
> >          return repr(list(self))
>
> >      def append(self, item):
> >          self.__delcached()
> >          self.__parent._data.append(DictOfListElement(self.__key, item))
>
> >      def __getitem__(self, index):
> >          return self.__cached[index]
>
> >      def __setitem__(self, index, value):
> >         self.__delcached()
> >          [item for item in self.__parent._data if item.key ==
> > self.__key][index].data = value
>
> >      # other list like methods
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to