python - Copy just the data columns from a SQLAlchemy object -
i have object
esc = escalation.query\ .filter(escalation.esc_id == esc_id).first()
and re-create of columns except primary key , foreign keys can create new re-create of object in database new relationships.
currently create constructor can take escalation instance can say
new_esc = escalation(esc)
but wondering if there built in feature sqlalchemy solves problem. looked @ session.merge don't want take entire state.
i think make_transient
looks great solution. not built-in, i've subclassed sqlalchemy.ext.declarative.declarativemeta
have custom __init__
, gave iteration methods, unpack instance values new instance this:
new_esc = escalation(**esc)
it kind of pain do, though. metaclasses fragile , wound brain.
python sqlalchemy flask-sqlalchemy
No comments:
Post a Comment