so have parent child relationship between topic models relationship represented class:
class parentchildrelation(db.model): __tablename__ = 'parent_child_relation' id = db.column(db.integer, primary_key=true) child_topic_id = db.column(db.integer, db.foreignkey('topic.id'), nullable=false) parent_topic_id = db.column(db.integer, db.foreignkey('topic.id'), nullable=false) and topics defined such:
class topic(db.model): __tablename__ = 'topic' id = db.column(db.integer, primary_key=true) parent = db.relationship( 'topic', secondary='parent_child_relation', primaryjoin='topic.id == parentchildrelation.child_topic_id', secondaryjoin='topic.id == parentchildrelation.parent_topic_id' ) i'd have parent one-to-one relationship (i might change later on), comes instrumentedlist. there simple way of stating parent should one-to-one relationship such links directly topic model instead of being instrumentedlist?
so turns out had found correct answer, must have had typo :/. adding uselist=false did trick.
parent = db.relationship( 'topic', secondary='parent_child_relation', primaryjoin='topic.id == parentchildrelation.child_topic_id', secondaryjoin='topic.id == parentchildrelation.parent_topic_id', uselist=false )
Comments
Post a Comment