views:

95

answers:

0

Following suggestions, I am converting my project to declarative sqlalchemy class definitions. This allows me to define relations as strings ( a=relation('myotherclass'), instead of relation(myotherclass) ), and avoid cross importing issues.

My question is how do I define column_properties the same way.

This is sort of what I have (non-declarative)

mapper(myobj,myobj_table, properties = { 
            'count':column_property(select([func.count(otherclass_table.c.myobj_id)],
            (otherclass_table.c.myobj_id==myobj_table.c.id) & 
            (otherclass_table.c.status_id <= 3))) })

I would like to do something of the sort:

count = column_property(select([func.count("otherclass.myobj_id")],
            ("otherclass.myobj_id"==myobj.id) & 
            ("otherclass.status_id" <= 3))) })

This way I don't have to import otherclass (or just the table itself - which is what I did previously) when defining myobj. I am still having some issues understanding how this is supposed to be structured.