[sqlalchemy] Re: Don't want foreign key on child to be updated when parent is updated

2019-02-26 Thread Sergey V.
This thing is called referential integrity (https://en.wikipedia.org/wiki/Referential_integrity) and is enforced on the database level - you can't have a value in Child.parent_id which is not in Parent.id. The ForeignKey creates a constraint in the database which ensures the referential

[sqlalchemy] Don't want foreign key on child to be updated when parent is updated

2019-02-26 Thread Daniel Leon
Suppose I have a Parent and Child table with Child having parent_id = Column(Integer, ForeignKey('parent.id'), back_populates= 'children', nullable=False) parent = relationship('parent') and Parent having children = relationship('child', back_populates='parent') Then if I try to delete a Parent,

Re: [sqlalchemy] Using primary_join with back_populates

2019-02-26 Thread Mike Bayer
you are missing and_(): billing_addresses = relationship('Address', primary_join='and_(User.id==Address.id, Address.is_billing.is_(True))', uselist=True) On Tue, Feb 26, 2019 at 5:44 AM Pavel Pristupa wrote: > > Hi everybody! > > Is there a way to use primary_join with back_populates in the

[sqlalchemy] Using primary_join with back_populates

2019-02-26 Thread Pavel Pristupa
Hi everybody! Is there a way to use primary_join with back_populates in the following case? I have two entities (sorry, I may be wrong with the exact syntax): class User(Base): id = sa.Column(sa.Integer, primary_key=True) billing_addresses = relationship('Address',