SQL Alchemy handles adjacency structures just fine, e.g. a self-referential table node where foreign key node.parent_id relates to primary key node.id.
I have a less conventional model where a node has two parents (a genealogy database). In this, node.mat_id and node.pat_id relate to the maternal and paternal parent nodes respectively. SQL Alchemy is OK with this too:
mother = db.relationship("Node",
foreign_keys = "Node.mat_id", remote_side="Node.id")
father = db.relationship("Node",
foreign_keys = "Node.pat_id", remote_side="Node.id")
(using Declarative).
So getting both parents of a node is straight forward. My problem is with getting the children of a node with this setup. I can't find a way to set up a relationship the equivalent of:
offspring = db.relationship("Node",
foreign_keys = "Node.mat_id | Node.pat_id")
The best I have managed is to declare mat_offspring and pat_offspring relationships separately and create a member function offspring() that returns the appropriate one. It works but seems inelegant. Is there a better and more conventional way?