On Thu, Jul 4, 2019, at 8:14 AM, natsjoo sodillepa wrote: > @Simon. > Interesting point. I create the DB and the instances in one script. The data > in the db seems to be correct. > However the error occurs in a second script which almost is like this: > > import ClassA2 > > ... create session ... > > objectA2 = session.query(ClassA2).first() > > for objectA1 in objectA2.list_objectA1: > objectA1.do_something() > > So, no here I don't import ClassA1, but I shouldn't, should I (?). > > The error occurs on entering the for loop.
SQLAlchemy has to know about all the classes before you do a query that's going to refer to a remote class' polymorphic_identity, so somewhere you have to make sure the module was imported. > > > > El jueves, 4 de julio de 2019, 13:16:12 (UTC+2), Simon King escribió: >> SQLAlchemy doesn't care if your classes are defined in a single file >> or multiple files. >> >> When you got the error, is it possible that you hadn't imported >> moduleB? If you haven't imported it, SQLAlchemy will have no idea that >> ClassB exists. >> >> Simon >> >> On Thu, Jul 4, 2019 at 11:53 AM natsjoo sodillepa <snat...@gmail.com> wrote: >> > >> > Hi all, >> > >> > I got an "No such polymorphic_identity" error in the following situation: >> > - I use Declerative and joined table polymorfism style >> > - moduleA defines Base, and a lot of Classes, one of them ClassA1(Base) >> > and ClassA2(Base) >> > - moduleB contains a subclassed ClassB(ClassA1) >> > - ClassA2 contains a 1:n relation with ClassA1 >> > >> > when I try to get the list of ClassA1 objects of ClassA2 I get a "No such >> > polymorphic_identity" >> > error. >> > >> > However, if I put everything in the same file things work fine. >> > >> > So my question is: can I put subclasses in different modules and if so: >> > how? >> > >> > Kind regards, >> > Nacho >> > >> > -- >> > 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. >> > To post to this group, send email to sqlal...@googlegroups.com. >> > 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/53a77b0e-b28c-4c1d-a54a-ffac09cfb5be%40googlegroups.com. >> > >> > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/a4af5e8f-d17a-4fd8-a0d4-5fb6a058b998%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/a4af5e8f-d17a-4fd8-a0d4-5fb6a058b998%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 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. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/032d8832-54e2-45cc-9cb4-0673c284017e%40www.fastmail.com. For more options, visit https://groups.google.com/d/optout.