On Tue, Mar 6, 2018 at 8:36 PM, Harshvardhan Gupta
<harshsay...@gmail.com> wrote:
> I tried to use AbstractConcreteBase for polymorphic relationships , but I am
> getting errors. The examples in sqlalchemy cover normal polymorphism well,
> but not those with Abstract Base classes.
>
>
> I have already asked a question on stack overflow .
>
> The gist of the question is:
>
> class OrderItem(Dictifiable, AbstractConcreteBase, db.Model):
>     pass
>
>
> class OrderTestItem(OrderItem):
>     order_id = Column(Integer, ForeignKey("order.id"), primary_key=True)
>     test_id = Column(Integer, ForeignKey("test.id"), primary_key=True)
>
>     test = relationship('Test')
>     order = relationship('Order')
>
>     __mapper_args__ = {
>         'polymorphic_identity': 'order_test_item',
>         'concrete': True
>     }
>
>
>
> class Order(Dictifiable, db.Model): # This class has a relation to the
> polymorphic class
>
>     id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
>
>     user_id = Column(Integer, ForeignKey('user.id'))
>
>     user = relationship('User')
>     items = relationship('OrderItem')
>
>
> I query like :
>
> pjoin = polymorphic_union({
>     'order_test_item': OrderTestItem.__table__,
> }, 'type', 'pjoin')
>
> order_items =
> with_polymorphic(OrderItem,[OrderTestItem],selectable=pjoin,flat=True)
>
> And my actual query :
>
> order = Order.query.join(Order.items.of_type(order_items)).all()
>
>
> I would like to know what the correct way to query these tables is, how to
> eager load polymorphic tables, and how to filter on the relationships.

looks correct to me.  what is "the error" ?   can you provide full
MCVE + complete stack trace?



>
> I plan to send a pull request with an example of these test cases after I
> know the answers myself.
>
>
> --
> 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 post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to