Thanks for the quick reply Michael. I would love to hear what you can find 
out about it.

I have what I think is a pretty horrible and dirty “solution”. But it 
*seems* to work. What I’ve done is to assign the key attribute of columns 
like this:

from collections import namedtuple

MyBundleAttr = namedtuple('MyBundleAttr', ['attr', 'key'])
class MyBundle(Bundle):

    def __init__(self, name, *exprs, **kw):
        new_exprs = []
        for expr in exprs:
            # Support custom Bundle attr keys. I don't know the side-effects...
            if isinstance(expr, MyBundleAttr):
                new_expr = expr.attr
                new_expr.key = expr.key
            else:
                new_expr = expr
            new_exprs.append(new_expr)
        super().__init__(name, *new_exprs, **kw)

And then I use the newly created MyBundleAttr like this:

primate_bundle = MyBundle(
    'primate',
    Primate.name,
    MyBundle('wooden_tool', *[
        WoodenTool.id,
        WoodenTool.name,
        MyBundleAttr(WoodenToolCategory.name, 'category'),
    ]),
    MyBundle('solid_tool', *[
        SolidTool.id,
        SolidTool.name,
        MyBundleAttr(SolidToolCategory.name, 'category'),
    ]),
    single_entity=True,
)

I’m guessing this could cause all kinds of side-effects… Right?
​

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to