On Fri, Jun 21, 2019, at 7:22 AM, Dmytro Starosud wrote:
> Base class `A1` contains `polymorphic_identity` (along with
> `polymorphic_on`), but `Query(A1)`doesn't produce where clause, whereas
> `Query(A2)` (where `A2` is subclass of `A1` with its own
> `polymorphic_identity`) does.
> Tried looking in docs with no success. I think I am just missing something.
> `from sqlalchemy import Column, Integer, String
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import Query, configure_mappers
> Base = declarative_base()
> class A1(Base):
__tablename__ = 'a1'
id = Column(Integer, primary_key=True)
poly_on = Column(String, nullable=False)
__mapper_args__ = {
'polymorphic_on': poly_on,
'polymorphic_identity': 'a1',
}
> class A2(A1):
__mapper_args__ = {
'polymorphic_identity': 'a2',
}
configure_mappers()
> print(Query(A1))
> # SELECT a1.id AS a1_id, a1.poly_on AS a1_poly_on
> # FROM a1
> print(Query(A2))
> # SELECT a1.id AS a1_id, a1.poly_on AS a1_poly_on
> # FROM a1
> # WHERE a1.poly_on IN (:poly_on_1)`
> I would expect `WHERE` clauses in both cases.
what would the first WHERE clause be limiting on ?
an A2 is an A1, so if you are querying for all A1 objects, you should get those
that are A2 as well.
if you want to affect how this works you can use the before_compile event to
add whatever filters you'd like, see the example at
https://github.com/sqlalchemy/sqlalchemy/wiki/FilteredQuery
>
> Originally posted here <https://stackoverflow.com/q/56701668/3151829>.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/941f0c3e-e541-4554-8b4a-570c28afec64%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/941f0c3e-e541-4554-8b4a-570c28afec64%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/ce1721a8-0a31-497f-8969-c79b8f786541%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.