Thanks for replying. 
I forgot to show the error. 
It is this: 

1054, "Unknown column 'pjoin.order_id' in 'on clause'") [SQL: "SELECT 
`order`.id AS order_id, `order`.rp_id AS order_rp_id, `order`.user_id AS 
order_user_id \nFROM `order` INNER JOIN (SELECT order_test_item.order_id AS 
order_id, order_test_item.test_id AS test_id, 'order_test_item' AS type \nFROM 
order_test_item) AS anon_1 ON `order`.id = pjoin.order_id"




On Wednesday, 7 March 2018 15:28:54 UTC-5, Mike Bayer wrote:
>
> On Tue, Mar 6, 2018 at 8:36 PM, Harshvardhan Gupta 
> <harsh...@gmail.com <javascript:>> 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+...@googlegroups.com <javascript:>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>. 
> > 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