The structure I have created is like below:
class Parent(Base): __tablename__ = 'parent' id = Field(
Integer, primary_key=True ) type_ =
Field( String(50), readonly=True )
__mapper_args__ = { 'polymorphic_on': type_, } class
ChildOne(Parent): __tablename__ = 'child_one' __mapper_args__ = {
'polymorphic_identity': 'child_one' } id = Field(
Integer, ForeignKey('parent.id'),
primary_key=True ) requested_type_one = Column(
Integer, nullable=False, ) delivered_type_one =
Column( Integer, nullable=False, ) is_done
= column_property( requested_type_one == delivered_type_one )
class ChildTwo(Parent): __tablename__ = 'child_two'
__mapper_args__ = { 'polymorphic_identity': 'child_two' }
id = Field( Integer, ForeignKey('parent.id'),
primary_key=True ) requested_type_two = Column(
Integer, nullable=False, ) delivered_type_two =
Column( Integer, nullable=False, ) is_done
= column_property( requested_type_two == delivered_type_two )
What I am looking for is to execute ORM query like this:
session.query(Parent).filter(Parent.is_done.is_(True)).all()
which raises `Parent class does not have is_done` error.
I want that parent class gets Child class's `is_done` based on different types
of child classes, I have tried to created `is_done` as `column_property` on
parent but I couldn't make it work. Also I tried using `hybrid_property` and
neither it is.
What should I do to make Parent class get `is_done` from its children?
stackoverflow link:
https://stackoverflow.com/questions/66024558/creating-column-sqlalchemy-property-on-parent-class-based-on-child-column-proper
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/1310342569.2406235.1612346870964%40mail.yahoo.com.