product_t = Product.__table__ product_flavor_t = ProductFlavor.__table__ product_t_a = product_t.alias()
op.add_column(u'product', sa.Column('servings', sa.Integer(), nullable=True)) op.add_column(u'product', sa.Column('flavors_count', sa.Integer(), nullable=True)) servings = select([func.coalesce(func.avg(product_flavor_t.c.size), 0)]).\ select_from(product_t_a.outerjoin(product_flavor_t)).\ where(product_t.c.id == product_t_a.c.id) flavors_count = select([func.count(product_flavor_t.c.id)]).\ select_from(product_t_a.outerjoin(product_flavor_t)).\ where(product_t.c.id == product_t_a.c.id) op.execute(product_t.update().values(servings=servings, flavors_count=flavors_count)) op.alter_column(u'product', 'servings', nullable=False) op.alter_column(u'product', 'flavors_count', nullable=False) -- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.