Thanks Mike. This is good to know.

On Tuesday, January 7, 2020 at 5:53:19 PM UTC-8, Mike Bayer wrote:
>
> to accomplish this you would need to rewrite the 
> orm.util.polymorphic_union function to include these additional expressions 
> within each SELECT under a common label name, then override the part of 
> AbstractConcreteBase which applies the polymorphic_union in order to 
> accomplish this.
>
> These two functions could be enhanced to support additional expressions 
> added to the polymorphic_union however that's not available right now.
>
> Otherwise, you need to select from TableA and TableB explicitly and write 
> the UNION directly.
>
> if this in fact a "toy" example then I would say you're better off not 
> using concrete inheritance as it is not very fluent.
>
>
>
>
> On Tue, Jan 7, 2020, at 1:38 PM, Damian Yurzola wrote:
>
> Folks I have this toy example I've sanitized.
>
> class TableBase(AbstractConcreteBase, Base):
>     pass
>
>
> class TableA(TableBase):
>     __tablename__ = "table_a"
>     __mapper_args__ = {
>         "polymorphic_identity": "A",
>         "concrete": True,
>     }
>
>     v0 = Column(Integer)
>
>     @hybrid_property
>     def magic(self):
>         return self.v0 * 100
>
>     @magic.expression
>     def magic(cls):
>         return cls.v0 * 100
>
>
> class TableB(TableBase):
>     __tablename__ = "table_b"
>     __mapper_args__ = {
>         "polymorphic_identity": "B",
>         "concrete": True,
>     }
>     v0 = Column(Integer)
>
>     @hybrid_property
>     def magic(self):
>         return self.v0 * 10
>
>     @magic.expression
>     def magic(cls):
>         return cls.v0 * 10
>
>
> When I query at the top level:
>
> print(Query([TableBase.magic]).limit(1).statement) 
>
> I get
>
> AttributeError: type object 'TableBase' has no attribute 'magic'
>
>
> I've tried a bunch of things, most of them point to the fact that the 
> hybrid_property is not being rendered in the subquery.
> I did solve it by moving the hybrid_property into the abstract class, 
> though I want the particularities of a table to stay with the table 
> definition and not at the union level.
>
> Thoughts? Ideas?
>
> Thanks!!!
>
> --Damian
>
>
> --
> 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 sqlal...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/fee90588-8431-4e51-9f3a-39af6544bde1%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/fee90588-8431-4e51-9f3a-39af6544bde1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/9b75f57a-204e-4e6d-b4d1-d606498274b1%40googlegroups.com.

Reply via email to