I think everything you have said is correct. If you use "relationship"
to create a link from class A to class B, then "backref" is just a
shortcut to create a corresponding relationship in the other
direction, from B to A. They are entirely optional; you don't have to
create a backref if you don't
Thanks Simon for your help. I have been playing around with the backref and
I think I understand it, I just want to clarify my understanding before
"close" this question.
1. There is no requirements to set a backref to any table, it could be
the main table or the table that contains the
If you're using backrefs, it doesn't really matter which end of the
relationship you configure. In the example above, it would be just as
legitimate to remove the source_node and target_node relationship
definitions, and define them on the NodesModel instead:
class NodesModel(Base):
Hi Simon,
Thanks for the help just a follow up to clarify this.
Does this mean if I place the backref in the relationships definition in
the Relationships model, this works the same way as the backref in a parent
model? I'm asking because backref have all been placed in the parent models
and for
foreign_keys and backref are different concepts. foreign_keys is a
hint to SQLAlchemy on how to create the join condition between 2
classes. backref specifies a property that should be created on the
other end of the relationship to allow you to follow the relationship
in the other direction.
For
Hi there,
Sorry, I've actually found the solution after I've posted my question again.
But I have to ask.
I'm doing this in my relationships model:
source_node = relationship("NodesModel", foreign_keys=[source_node_id])
target_node = relationship("NodesModel", foreign_keys=[target_node_id])
Hi Simon,
I've read and I've tried a number of what is written but I still can't
solve it.
I've done this:
class RelationshipsModel(db.Model):
__tablename__ = 'relationships'
source_node_id = db.Column(db.BigInteger, db.ForeignKey('nodes.id'),
primary_key=True)
target_node_id =
On Wed, May 29, 2019 at 10:08 AM Desmond Lim 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 =