Hi all, I have a model with three classes, Job, Page and PageVersions. A job has many pages and a page has many versions.
Now, I use a combined primary key for Page and PageVersions (see code below) - and have "normal" relations to each other (job.pages, page.job, page.versions, pageversion.page etc.) Only one version of a page is "active", and is marked so with a boolean attribute on PageVersion. I would like to add a property on Page that points to that version (this would of course create a circular reference) - something like page.currentversion - with a corresponding Integer column "currentversion" on the pages table. Is this possible with SA given the kind of combined keys I'm using? The fallback solution is to do an eager-load on all pageversions attached to a page and handle this with a regular python property. Arnar jobs = Table("jobs", __meta__, Column("jobno", Unicode(15), primary_key=True), Column("created", DateTime, nullable=False, default=datetime.now)) class Job(object): pass mapper(Job, jobs) pages = Table("pages", __meta__, Column("jobno", Unicode(15), ForeignKey("jobs.jobno"), primary_key=True), Column("pagename", Unicode(30), primary_key=True), Column("created", DateTime, nullable=False, default=datetime.now)) class Page(object): pass mapper(Page, pages, properties={ 'job': relation(Job, backref=backref('pages', cascade="all, delete-orphan")) }) pageversions = Table("pageversions", __meta__, Column("jobno", Unicode(15), primary_key=True, ForeignKey("pages.jobno")), Column("pagename", Unicode(30), primary_key=True, ForeignKey("pages.pagename")), Column("version", Integer, primary_key=True), Column("created", DateTime, nullable=False, default=datetime.now), Column("active", Boolean, nullable=False, default=True)) class PageVersion(object): pass mapper(PageVersion, pageversions, properties={ 'page': relation(Page,backref=backref('versions', cascade="all, delete-orphan", lazy=False, order_by=pageversions.c.version)) }) _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users