Ok, I'll try to build this query in sql. thanks :) Le lun. 13 mai 2019 à 17:43, James Fennell <jamespfenn...@gmail.com> a écrit :
> I think Mike's suggestion was to construct the raw SQL string you want, > then reverse engineer to get the correct SQL Alchemy code, which you can > then use with your different models. For complicated SQL logic I think this > is a good practice in general. > > You current question seems like a general SQL question rather than > something specific to SQL Alchemy. After you've the SQL, we could discuss > the reverse engineering. > > On Mon, May 13, 2019, 10:37 AM Scheck David <da...@sphax.it wrote: > >> the problem is that I can't use SQL for this because this is a mixins >> that I use for several objects (tables) because they all have this status >> structure... yes it's quite difficult to do : >> >> right now I'm on this stage, but still don't work >> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\ >> .group_by(Object).with_entities(Object, >> func.max(Status.datum).label("status_datum")).subquery() >> >> self.session.query(Object).join((sub, sub.c.id == Status.id))\ >> .filter(sub.c.statustype_id > 50) >> >> Le lun. 13 mai 2019 à 16:26, Mike Bayer <mike...@zzzcomputing.com> a >> écrit : >> >>> Hi - >>> >>> I was hoping someone could jump in on this. >>> >>> do you know the SQL that you want to emit? E.g. plain SQL string. I >>> can help you do that part. >>> >>> >>> On Mon, May 13, 2019 at 9:11 AM Scheck David <da...@sphax.it> wrote: >>> > >>> > I think I'm near but I can't finish : >>> > >>> > for all the structure : https://dpaste.de/fek5#L >>> > >>> > and here my query : >>> > >>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\ >>> > .group_by(Object).with_entities(Object, >>> func.max(Status.datum).label("status_datum")).subquery() >>> > >>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\ >>> > .filter(sub.c.statustype_id > 50) >>> > >>> > but status type not reachable. >>> > >>> > >>> > -- >>> > 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/fe2da543-2710-4b44-9f88-e68c5e35faea%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 a topic in the >>> Google Groups "sqlalchemy" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe. >>> To unsubscribe from this group and all its topics, 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/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> -- >> >> With kindest regards, >> >> >> *David SCHECK* >> >> PRESIDENT/DEVELOPER >> >> [image: Signature Logo Sphax Bleu-01.png] >> >> Phone: +32 4 87 86 70 12 >> Visit our website ! https://www.sphax.org >> >> -- >> 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/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com >> <https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.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 a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe. > To unsubscribe from this group and all its topics, 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/CALDF6i1aehirZNM3ac60nw8N-A8Hbs2JoALx4p_WEesoqOn%2BZg%40mail.gmail.com > <https://groups.google.com/d/msgid/sqlalchemy/CALDF6i1aehirZNM3ac60nw8N-A8Hbs2JoALx4p_WEesoqOn%2BZg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- With kindest regards, *David SCHECK* PRESIDENT/DEVELOPER [image: Signature Logo Sphax Bleu-01.png] Phone: +32 4 87 86 70 12 Visit our website ! https://www.sphax.org -- 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/CAOPG6se7fdprvhftVjVUcN6%2BP%3DwdeAOLahfuBH7kKqgGEOZNVg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.