On Nov 27, 2011, at 1:15 AM, Geo wrote: > 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).\ > filter(Product.price*payback_pc- > Capital_invest.capital_payback<=0).\ > > group_by(Capital_invest.member_id).subquery() > > buy_product_count = session.query(Capital_invest.member_id, > func.count().label("count")).\ > group_by(Capital_invest.member_id).subquery() > > x_members = session.query(Distributor).\ > join(paid_120_count, > paid_120_count.c.member_id==Distributor.id).\ > join(buy_product_count, > buy_product_count.c.member_id==Distributor.id).\ > > filter(paid_120_count.c.count==buy_product_count.c.count).\ > filter(Distributor.quali_bonus==True) > > > So the distributor is the center table joins two queries. The Query > returns data without problem. But i can't update the result data > subsequently, for example > > for member in x_members: > member.name ="xxxxx" > > The sqlalchemy just simply do nothing. I have to do this: > > for member in x_members: > member.name ="xxxxx" > > dist = session.query(Distributor).get(member.id) > dist.name = "xxxxx"
did you close out the Session before you iterated through x_members ? This test will ensure you're doing things correctly: for member in x_members: dist = session.query(Distributor).get(member.id) assert dist is member the identity map will ensure they are the same instance, *if* you are operating on x_members as present in the Session. If the Session got closed before you iterated, you'd need to not do that. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.