Add backref cascade and make changes to the spot where we delete so it loads objects into memory and then uses the SQLAlchemy plumbing to make sure that the db object gets cleaned up.
This commit is contained in:
parent
6ce560cc2d
commit
b4ecb0f97a
|
@ -138,7 +138,9 @@ def delete_workflow_specification(spec_id):
|
|||
# Delete all events and workflow models related to this specification
|
||||
for workflow in session.query(WorkflowModel).filter_by(workflow_spec_id=spec_id):
|
||||
StudyService.delete_workflow(workflow.id)
|
||||
session.query(WorkflowSpecModel).filter_by(id=spec_id).delete()
|
||||
# the cascade feature doesn't work if
|
||||
deleteSpec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
|
||||
session.delete(deleteSpec)
|
||||
session.commit()
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import marshmallow
|
|||
from marshmallow import EXCLUDE,fields
|
||||
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import backref
|
||||
|
||||
from crc import db
|
||||
from crc.models.file import FileModel, FileDataModel
|
||||
|
@ -46,9 +47,9 @@ class WorkflowLibraryModel(db.Model):
|
|||
library_spec_id = db.Column(db.String, db.ForeignKey('workflow_spec.id'), nullable=True)
|
||||
parent = db.relationship(WorkflowSpecModel,
|
||||
primaryjoin=workflow_spec_id==WorkflowSpecModel.id,
|
||||
backref='libraries')
|
||||
backref=backref('libraries',cascade='all, delete'))
|
||||
library = db.relationship(WorkflowSpecModel,primaryjoin=library_spec_id==WorkflowSpecModel.id,
|
||||
backref='parents')
|
||||
backref=backref('parents',cascade='all, delete'))
|
||||
|
||||
|
||||
class WorkflowSpecModelSchema(SQLAlchemyAutoSchema):
|
||||
|
|
Loading…
Reference in New Issue