I finished by a query like that : 

        last_statuses = aliased(statussen_table_name, 
self.session.query(getattr(statussen_table_name, object_name),
                                                                        
statussen_table_name.status_id).join(Status).order_by(Status.datum.desc()).limit(1).subquery().lateral())
        return 
self.session.query(self.cls).join(last_statuses).filter(Status.statustype_id 
> 50).all()

the problem is that there is a problem in the query : 

sqlalchemy.exc.InvalidRequestError: Select statement 'SELECT 
statussen.datum 

FROM (SELECT personen.id AS personen_id 

FROM statussen, personen JOIN LATERAL (SELECT personen_statussen.persoon_id 
AS persoon_id, personen_statussen.status_id AS status_id 

FROM personen_statussen JOIN statussen ON statussen.id = 
personen_statussen.status_id ORDER BY statussen.datum DESC

 LIMIT :param_1) AS anon_2 ON personen.id = anon_2.persoon_id 

WHERE statussen.statustype_id > :statustype_id_1) AS anon_1, 
personen_statussen 

WHERE statussen.id = personen_statussen.status_id' returned no FROM clauses 
due to auto-correlation; specify correlate(<tables>) to control correlation 
manually.

-- 
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/f7fef252-8fc6-4cb5-a8e4-1270cfacab21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to