Re: [sqlalchemy] possible way of changing the relationship loading strategy in the runtime, on the class level or instance level

2015-05-11 Thread Geo
at 11:23:17 PM UTC+8, Michael Bayer wrote: On 5/11/15 11:16 AM, Geo wrote: Ok, I got this working by adding the following code into the base class: parent_lazy = relation( 'Node', remote_side=[id], backref=backref( 'children_lazy', collection_class

Re: [sqlalchemy] SA doesn't update table

2011-12-01 Thread Geo
Well, my case is a bit different. I'm writing a nightly running batch script. And this script is not running inside pyramid context, which means it is not the model that called from the framework. Instead, I arrange it to run by system cron. But, I'm trying to utilize the pyramid environment

Re: [sqlalchemy] SA doesn't update table

2011-12-01 Thread Geo
Ok I found the solution, just move the first query into the transaction body: import transaction try: transaction.begin() x_members = session.query(Distributor)... for member in x_members: . except: transaction.abort() BTW, I'm using pyramid framework, which is using the

[sqlalchemy] SA doesn't update table

2011-11-27 Thread Geo
I have a query to join another two querys which are written as subqueries: paid_120_count = session.query(Capital_invest.member_id, func.count().label(count)).\ join(Product, Capital_invest.prod_id==Product.prodid).\

[sqlalchemy] Having problem with constructing update ...from... with sqlalchemy

2011-09-12 Thread Geo
I have a tested update ... from.. statement, like so: update distributors set lead_bonus = lead_bonus + a.sum_amt from ( select target_member as id, sum(amount) as sum_amt from bonus_gen_history where bonus_type=2 and sub_type=1 and source_member in (select

[sqlalchemy] use session inside the class

2011-09-01 Thread Geo
I have a self-reference table, class member: id upline_id = Column(Integer, ForeignKey('member.id')) status downlines = relationship('member', backref=backref('upline', remote_side=id)) def setUpline(self, upline_id) session =

[sqlalchemy] Question about Many to One relationship

2011-09-01 Thread Geo
I have tables which linked as a one to many relationship: user ---(one to many)--- order --(many to one)--product Product has been populated and served as a lookup table. class User: member_id purchase_total order = relationship(Order) def add_product(self,