def _compound_eager_statement(self, context):
    if context.order_by:
        order_by_col_expr = list(chain(*[sql_util.unwrap_order_by(o) for o in context.order_by]))
    else:
        context.order_by = None
        order_by_col_expr = []
    inner = sql.select((context.primary_columns + order_by_col_expr), context.whereclause, from_obj=context.froms, use_labels=context.labels, order_by=context.order_by, **self._select_args)
    for hint in self._with_hints:
        inner = inner.with_hint(*hint)
    if self._correlate:
        inner = inner.correlate(*self._correlate)
    inner = inner.alias()
    equivs = self.__all_equivs()
    context.adapter = sql_util.ColumnAdapter(inner, equivs)
    statement = sql.select(([inner] + context.secondary_columns), use_labels=context.labels)
    statement._for_update_arg = context._for_update_arg
    from_clause = inner
    for eager_join in context.eager_joins.values():
        from_clause = sql_util.splice_joins(from_clause, eager_join, eager_join.stop_on)
    statement.append_from(from_clause)
    if context.order_by:
        statement.append_order_by(*context.adapter.copy_and_process(context.order_by))
    statement.append_order_by(*context.eager_order_by)
    return statement
def _compound_eager_statement(self, context):
    if context.order_by:
        order_by_col_expr = list(chain(*[sql_util.unwrap_order_by(o) for o in context.order_by]))
    else:
        context.order_by = None
        order_by_col_expr = []
    inner = sql.select((context.primary_columns + order_by_col_expr), context.whereclause, from_obj=context.froms, use_labels=context.labels, order_by=context.order_by, **self._select_args)
    for hint in self._with_hints:
        inner = inner.with_hint(*hint)
    if self._correlate:
        inner = inner.correlate(*self._correlate)
    inner = inner.alias()
    equivs = self.__all_equivs()
    context.adapter = sql_util.ColumnAdapter(inner, equivs)
    statement = sql.select(([inner] + context.secondary_columns), use_labels=context.labels)
    statement._for_update_arg = context._for_update_arg
    from_clause = inner
    for eager_join in context.eager_joins.values():
        from_clause = sql_util.splice_joins(from_clause, eager_join, eager_join.stop_on)
    statement.append_from(from_clause)
    if context.order_by:
        statement.append_order_by(*context.adapter.copy_and_process(context.order_by))
    statement.append_order_by(*context.eager_order_by)
    return statement