Hello,
I am struggling with this case and so far, I haven't seen on documentation
or on the different posts, a way to solve my problem.
Firstly, I cannot have a ForeignKey linking Child to Parent because Parent
has a polymorphic identity, and PostgreSQL is not dealing with ForeignKey
in such cases. Let's say ParentA is a Parent.
So I have to define relationship between Child and Parent "manually"
Thus, I have this :
class Child(SaBaseClass):
parent_id = Column(Integer, index=True, nullable=True)
parent = relationship('Parent', primaryjoin='foreign(Child.parent_id)
== Parent.id', lazy='joined', uselist=False, foreign_keys='Child.parent_id')
class Parent(SaBaseClass):
children = relationship('Child', primaryjoin='Child.parent_id ==
foreign(Parent.id), backref='children', cascade='all, delete-orphan',
uselist=True, lazy='joined', single_parent=True)
So a child is linked to only one parent, and a parent can be linked to
several children, and when I delete a Child instance I would like to
"unlink" it from its Parent. When trying to delete a child instance I get
"Dependency rule tried to blank-out primary key column parent.id on
instance 'ParentA', which makes me think it's trying to delete Parent
instance...
If someone has a clue of what's wrong with my definition of the
relationship, thanks in advance for your help !
Isabelle
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.