Hello, Our data model for a structure named PlateWell in our software utilizes a singly linked-list structure with a field for a parent PlateWell. We are adding another field pointing to the root PlateWell of the link list to improve runtime of certain important operations, however the relationships are not loading. Here is the abridged model.
class PlateWell(db.Model): __tablename__ = 'plate_wells' id = db.Column(db.Integer, primary_key=True) parent_well_id = db.Column(db.Integer, db.ForeignKey('plate_wells.id'), index=True) root_well_id = db.Column(db.Integer, db.ForeignKey('plate_wells.id'), index=True) parent_well = db.relationship( 'PlateWell', uselist=False, lazy='noload', remote_side=[id], foreign_keys=[parent_well_id]) root_well = db.relationship( 'PlateWell', uselist=False, lazy='noload', remote_side=[id], foreign_keys=[root_well_id]) At the root entry, the root_well_id is equal to id and parent_well_id is set to None. Prior to adding the root relationship, the model loaded the parent_well relationship without the foreign_keys kwarg. This relationship was fully functional. Now, any time a plate well is loaded via a query like well = PlateWell.query.filter(PlateWell.id == well.plate_well_id).one() both parent_well and root_well are set to None, despite both foreign key id fields containing an id that does relate to another entry. We've attempted adding explicit primaryjoin kwargs, expiring the session to clear the cache, but neither seems to work. Is there a trick to loading multiple self-referential relationships or some other change we can make to properly load these relationships? -- This e-mail is private and confidential and is for the addressee only. If misdirected, please notify us by telephone, confirming that it has been deleted from your system and any hard copies destroyed. You are strictly prohibited from using, printing, distributing or disseminating it or any information contained in it save to the intended recipient. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.