Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
I've got the expression part of the hybrid properties working now, using an alias: @friend_code_usage_count.expression def friend_code_usage_count(cls): alias = aliased(AffinionCode) return select([func.count(alias.Rtid)]). \ where(alias.PromoCode ==

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
I do have a follow up, actually. If I wanted to make friend_code_usage_count a column property so that it was always loaded with the object, how would I do that? It doesn't look like I can add alias = aliased(AffinionCode) within the class definition. Where/how would I define the alias?

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread Mike Bayer
For a fancy column_property like that you likely need to define it after the fact and attach it to the class. There's some new features I have in the works for 1.0 to make that easier. The general idea is: class MyClass(Base): # ... alias = aliased(MyClass) stmt =

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
cool, thanks again. On Monday, August 11, 2014 1:19:30 PM UTC-5, Michael Bayer wrote: For a fancy column_property like that you likely need to define it after the fact and attach it to the class. There's some new features I have in the works for 1.0 to make that easier. The general

[sqlalchemy] self-referential relationship and aliases

2014-08-10 Thread dweitzenfeld
I'm having trouble getting a self-referential table to alias correctly. In the example below, Jack was given a family code of 'FOO.' He shares this with his family member Jill, who enters it as her PromoCode. RtidPromoCodeFamilyCode JackBARFOO JillFOO ​ This is my sqlalchemy class for the

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-10 Thread Michael Bayer
it seems like you might want to make use of aliased() in those @hybrid_properties you have; if you do an equijoin from AffinionCode.something == cls.somethingelse, “cls” here is AffinionCode again. One side should be an aliased() object. On Aug 10, 2014, at 8:01 PM, dweitzenfeld