On Wed, May 29, 2019 at 10:08 AM Desmond Lim <limwen...@gmail.com> wrote:
>
> Hi there,
>
> I'm been puzzling over this and still can't find answer.
>
> I have 2 tables:
>
> Nodes:
>
> class NodesModel(db.Model):
>     __tablename__ = 'nodes'
>
>     id = db.Column(db.BigInteger, primary_key=True)
>     project_uuid = db.Column(UUID(as_uuid=True), 
> db.ForeignKey('projects.uuid'))
>     name = db.Column(db.String(50), nullable=False)
>     size = db.Column(db.Integer, nullable=False)
>
>     posts_nodes = relationship("PostsNodesModel", backref="nodes")
>     relationships = relationship("RelationshipsModel", backref="nodes")
>
> Relationships:
>
> class RelationshipsModel(db.Model):
>     __tablename__ = 'relationships'
>
>     source_node_id = db.Column(db.BigInteger, db.ForeignKey('nodes.id'), 
> primary_key=True)
>     target_node_id = db.Column(db.BigInteger, db.ForeignKey('nodes.id'), 
> primary_key=True)
>     strength = db.Column(db.Integer, nullable=False)
>
> I'm getting errors on this line:
>
> relationships = relationship("RelationshipsModel", backref="nodes")
>
> And I know it is because my Relationships table has the Nodes table as a 
> foreign key twice. But I have not idea how do I create 2 relationships to the 
> Relationships table?
>

I assume the error you are getting is something like "Could not
determine join condition..."? In which case, you probably need this
section of the docs:

https://docs.sqlalchemy.org/en/13/orm/join_conditions.html#handling-multiple-join-paths

Hope that helps,

Simon

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexczSoXe-GCrfDB%2BD6tisADXkz1EBqtjhyMz2La58tL7yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to