Hi, this is probably extremely easy but I've only recently started using SQLAlchemy and I simply cannot manage to model the following relations:
+--------------+ +------------+ | NodeRevision | | Node | +--------------+ 1 +------------+ | vid |<------- | | | | \ 1 | | | | 1..* --\------>| nid | | nid |<-----/ \ | | | | \ 1 | | +--------------+ -----| vid | +------------+ The diagram depicts the following relations: * A Node has a latest_revision (Node.vid --> NodeRevision.vid) * A Node has many revisions (Node.nid --> NodeRevision.nid) * A NodeRevision belongs to a Node (NodeRevision.nid --> Node.nid). So far I've managed to get the following: class Node(Base): __tablename__ = "node" nid = Column(Integer, primary_key=True) vid = Column(Integer, ForeignKey("node_revisions.vid")) latest_revision = relation("NodeRevision") class NodeRevision(Base): __tablename__ = "node_revisions" vid = Column(Integer, primary_key=True) nid = Column(Integer) As you can see the only relation modeled here is the Node.last_revision relation. Note how I've left out NodeRevision.nid = Column(Integer, ForeignKey(Node)) because if I add it SQLAlchemy will immediately complain that it needs a primaryjoin argument (and whatever I try nothing works). I've searched the mailing list and there were a couple of discussions about circular dependencies but I didn't quite understand what was being said and how to adapt the examples to my situation. The relations most likely also need to take into account that Node eventually needs to have a valid vid and NodeRevision needs to have a valid nid. The documentation for the post_update argument on a relation describes this situation perfectly.[1] However, as you can tell, I haven't even gotten that far. Any help would be greatly appreciated. Thanks. References: [1] http://tinyurl.com/cqhk8y Best regards, Bruce
signature.asc
Description: OpenPGP digital signature