Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Desmond Lim
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

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-29 Thread Mike Bayer
On Wed, May 29, 2019, at 6:22 AM, Chris Wilson wrote: > Hi all, > > Thanks for the replies! Sorry, perhaps I wasn't clear, this is just a minimal > example. We are actually storing serialized objects in a column, which can be > e.g. dicts or lists of (dehydrated) SQLAlchemy objects, numpy

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Simon King
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):

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Desmond Lim
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

Re: [sqlalchemy] Filter query. Exclude some records by related model

2019-05-29 Thread Simon King
On Wed, May 29, 2019 at 11:46 AM kosta wrote: > > Hi everyone! > > I can't solve my issue by myself, could anyone has advice on this. > > > I've models (simplified): > class Tournament(Base): > id = Column(UUID(as_uuid=True), primary_key=True) > owner_id = Column(UUID(as_uuid=True),

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Simon King
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

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Desmond Lim
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])

[sqlalchemy] Filter query. Exclude some records by related model

2019-05-29 Thread kosta
Hi everyone! I can't solve my issue by myself, could anyone has advice on this. I've models (simplified): class Tournament(Base): id = Column(UUID(as_uuid=True), primary_key=True) owner_id = Column(UUID(as_uuid=True), ForeignKey('user.id', ondelete=' CASCADE'), nullable=False) owner =

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Desmond Lim
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 =

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-29 Thread Chris Wilson
Hi all, Thanks for the replies! Sorry, perhaps I wasn't clear, this is just a minimal example. We are actually storing serialized objects in a column, which can be e.g. dicts or lists of (dehydrated) SQLAlchemy objects, numpy arrays, etc. It's much faster to store (both read and write) a

Re: [sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Simon King
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 =

[sqlalchemy] Child table with 2 relationships to parent

2019-05-29 Thread Desmond Lim
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 =