Fix issues with delete-cascade
The important tables `xml` and `registration` were not properly set for their `CASCADE` behavior, in addiiton `XML` needed to have the `single_parent` option enabled to allow for cascading-deletes (since otherwise a single entry could be referenced by an entry and a error.select-best-date
parent
4b1c0b5f1d
commit
0a8fb1cde4
|
@ -39,7 +39,11 @@ class CCE(Core, Base):
|
|||
|
||||
volume_id = Column(Integer, ForeignKey('volume.id'))
|
||||
|
||||
registrations = relationship('Registration', backref='cce')
|
||||
registrations = relationship(
|
||||
'Registration',
|
||||
backref='cce',
|
||||
cascade='all, delete-orphan'
|
||||
)
|
||||
lccns = relationship('LCCN', backref='cce', cascade='all, delete-orphan')
|
||||
authors = relationship('Author',
|
||||
backref='cce', cascade='all, delete-orphan')
|
||||
|
|
15
model/xml.py
15
model/xml.py
|
@ -14,9 +14,11 @@ from sqlalchemy import (
|
|||
|
||||
from model.core import Base, Core
|
||||
|
||||
|
||||
@compiles(String, 'postgresql')
|
||||
def compile_xml(type_, compiler, **kw):
|
||||
return "XML"
|
||||
return 'XML'
|
||||
|
||||
|
||||
ENTRY_XML = Table(
|
||||
'entry_xml',
|
||||
|
@ -32,19 +34,24 @@ ERROR_XML = Table(
|
|||
Column('xml_id', Integer, ForeignKey('xml.id'), index=True)
|
||||
)
|
||||
|
||||
|
||||
class XML(Core, Base):
|
||||
__tablename__ = 'xml'
|
||||
id = Column(Integer, primary_key=True)
|
||||
xml_source = Column(String)
|
||||
|
||||
|
||||
entry = relationship(
|
||||
'CCE',
|
||||
secondary=ENTRY_XML,
|
||||
backref='xml_sources'
|
||||
backref='xml_sources',
|
||||
single_parent=True,
|
||||
cascade='all, delete-orphan'
|
||||
)
|
||||
|
||||
error_entry = relationship(
|
||||
'ErrorCCE',
|
||||
secondary=ERROR_XML,
|
||||
backref='xml_sources'
|
||||
backref='xml_sources',
|
||||
single_parent=True,
|
||||
cascade='all, delete-orphan'
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue