Initialize empty order_by dict to be populated later during the query call
Applies order_by queries on main model when it's used as a subquery. That way the subquery with limit and offset only on main model has proper sorting applied and correct models are fetched.
Applies orders_by from model Meta class (if provided), if it was not provided it was filled by metaclass so it's always there and falls back to pk column
Checks if limit or offset are set, the flag limit_sql_raw is not set and query has select_related applied. Otherwise we can limit/offset normally at the end of whole query.
result of the check :rtype: bool
Main entry point from outside (after proper initialization).
Extracts columns list to fetch, construct all required joins for select related, then applies all conditional and sort clauses.
Returns ready to run query with all joins and clauses.
ready to run query with all joins and clauses. :rtype: sqlalchemy.sql.selectable.Select
1 2 3
In order to apply limit and offset on main table in join only (otherwise you can get only partially constructed main model if number of children exceeds the applied limit and select_related is used)
Used also to change first and get() without argument behaviour. Needed only if limit or offset are set, the flag limit_sql_raw is not set and query has select_related applied. Otherwise we can limit/offset normally at the end of whole query.
The condition is added to filters to filter out desired number of main model primary key values. Whole query is used to determine the values.
Receives the select query (might be join) and applies: * Filter clauses * Exclude filter clauses * Limit clauses * Offset clauses * Order by clauses
Returns complete ready to run query.
expr: select expression before clauses :type expr: sqlalchemy.sql.selectable.Select
expresion with all present clauses applied :rtype: sqlalchemy.sql.selectable.Select
Although it should be created each time before the call we reset the key params anyway.