millerdev wrote:
>
>> > Thanks a lot for the tips on how to approach this problem. That's
>> > exactly what I needed.
>>
>> in 0.4 you'd get it off the impl (0.5 too, this is just uglier API):
>
> Excellent! Here's what I came up with as an initial solution:
>
> def poly_load(parent, collection, path):
>     def itersiblings(parent, path):
>         def iteritems(items, attr):
>             for item in items:
>                 for child in getattr(item, attr):
>                     yield child
>         items = [parent]
>         while path:
>             items = iteritems(items, path.pop(0))
>         return items
>     path = path.split(".")
>     assert len(path) % 2 == 0, "path must contain an even number of
> elements"
>     mid = len(path) / 2
>     gparent = parent
>     for attr in path[:mid]:
>         gparent = getattr(gparent, attr)
>     session = sqlalchemy.orm.session.object_session(parent)
>     backref = getattr(type(parent), collection).property.backref.key
>     itemclass = getattr(type(parent),
> collection).property.mapper.class_
>     qry = session.query(itemclass) \
>         .join([backref] + path[:mid]) \
>         .filter(type(gparent).table.c.id == gparent.id)
>     groups = defaultdict(list)
>     for item in qry:
>         groups[getattr(item, backref).id].append(item)
>     impl = getattr(type(parent), collection).impl
>     for sibling in itersiblings(gparent, path[mid:]):
>         if sibling.id in groups:
>             impl.set_committed_value(sibling._state, groups.get
> (sibling.id))
>

do i see correctly the implementation relies upon the presence of a
backref  ?  thats an example of a perfectly fine restriction that is not
good enough for core ;) .



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to