python - SQLAlchemy: transitive unique constraint -
i'm working on simple document management system each document can have number of versions , optionally number of tags point towards specific versions. users employ tags indicate version of document ready qa, production use, etc. each document, there should @ 1 tag of given name. i'm having trouble describing transitive relationship documents have versions , tags point versions, tag names never occur more once each document. here declarative tables far:
class document(base): __tablename__ = 'documents' id = column(integer, primary_key=true) name = column(string, nullable=false) versions = relationship('version', back_populates='document') tags = relationship('tag', secondary='versions') class version(base): __tablename__ = 'versions' id = column(integer, primary_key=true) document_id = column(integer, foreignkey('document.id')) name = column(string, nullable=false) contents = column(string, nullable=false) document = relationship('document', back_populates='versions') tags = relationship('tag', secondary='version') class tag(base): __tagname__ = 'tags' id = column(integer, primary_key=true) version_id = column(integer, foreignkey('versions.id')) name = column(string, nullable=false) version = relationship('version', back_populates='tags') document = relationship('document', secondary='versions')
i tried using uniqueconstraint
on tag
's document
, name
, didn't allow me use document
relationship column in constraint. read through the constraint tutorial, didn't find wanted.
Comments
Post a Comment