On 09/15/2011 04:13 PM, Michael Bayer wrote:
that is the case ....   you'd need to emit UPDATE against each table 
individually

I tried that quickly but still got the same error. My model looks like this (the full thing is at https://github.com/euphorie/Euphorie/blob/master/buildout/src/Euphorie/euphorie/client/model.py ):

class SurveyTreeItem(BaseObject):
    __tablename__ = "tree"
    __table_args__ = (schema.UniqueConstraint("session_id", "path"), {})

    id = schema.Column(types.Integer(), primary_key=True, autoincrement=True)
    type = schema.Column(Enum(["risk", "module" ]),
            nullable=False, index=True)
    __mapper_args__ = dict(polymorphic_on=type)


class Risk(SurveyTreeItem):
    """Answer to risk."""

    __tablename__ = "risk"
    __mapper_args__ = dict(polymorphic_identity="risk")

    identification = schema.Column(Enum([None, u"yes", u"no", "n/a"]))
    frequency = schema.Column(types.Integer())
    effect = schema.Column(types.Integer())
    probability = schema.Column(types.Integer())
    priority = schema.Column(Enum([None, u"low", u"medium", u"high"]))
    comment = schema.Column(types.UnicodeText())




and I'm trying to update it with this:


        old_tree = orm.aliased(SurveyTreeItem, name='old_tree')
        in_old_tree = sql.and_(
                old_tree.session_id == other.id,
                SurveyTreeItem.zodb_path == old_tree.zodb_path,
                SurveyTreeItem.profile_index == old_tree.profile_index)
        old_risk = orm.aliased(Risk, name='old_risk')
        is_old_risk = sql.and_(in_old_tree, old_tree.id == old_risk.id)
        identification = sql.select([old_risk.identification], is_old_risk)
        new_risks = session.query(Risk.__table__)\
                .filter(Risk.session == self)\
                .filter(sql.exists(
                    sql.select([SurveyTreeItem.id]).where(sql.and_(
                            SurveyTreeItem.id == Risk.id,
                            sql.exists([old_tree.id]).where(sql.and_(
                                in_old_tree, old_tree.type == 'risk'))))))
        new_risks.update({'identification': identification},
                synchronize_session=False)


I have tried to replace the JOINs with EXISTS tests so I can do the update against just Risk.__table__, but that still results in the same error.

Wichert.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to