# sqlalchemy 2.1.9 (MIT), harvested by tools/harvest_corpus.py
=== input
Return the :class:`_query.Query` object for use as a subquery.

        This method should be used within the lambda callable being used
        to generate a step of an enclosing :class:`.BakedQuery`.   The
        parameter should normally be the :class:`_query.Query` object that
        is passed to the lambda::

            sub_bq = self.bakery(lambda s: s.query(User.name))
            sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

            main_bq = self.bakery(lambda s: s.query(Address))
            main_bq += lambda q: q.filter(sub_bq.to_query(q).exists())

        In the case where the subquery is used in the first callable against
        a :class:`.Session`, the :class:`.Session` is also accepted::

            sub_bq = self.bakery(lambda s: s.query(User.name))
            sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

            main_bq = self.bakery(
                lambda s: s.query(Address.id, sub_bq.to_query(q).scalar_subquery())
            )

        :param query_or_session: a :class:`_query.Query` object or a class
         :class:`.Session` object, that is assumed to be within the context
         of an enclosing :class:`.BakedQuery` callable.

        
=== parse rest
short_description: 'Return the :class:`_query.Query` object for use as a subquery.'
long_description: |
  This method should be used within the lambda callable being used
  to generate a step of an enclosing :class:`.BakedQuery`.   The
  parameter should normally be the :class:`_query.Query` object that
  is passed to the lambda::
  
      sub_bq = self.bakery(lambda s: s.query(User.name))
      sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)
  
      main_bq = self.bakery(lambda s: s.query(Address))
      main_bq += lambda q: q.filter(sub_bq.to_query(q).exists())
  
  In the case where the subquery is used in the first callable against
  a :class:`.Session`, the :class:`.Session` is also accepted::
  
      sub_bq = self.bakery(lambda s: s.query(User.name))
      sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)
  
      main_bq = self.bakery(
          lambda s: s.query(Address.id, sub_bq.to_query(q).scalar_subquery())
      )
blank_after_short_description: True
blank_after_long_description: True
style: rest
- DocstringParam
  description: |
    a :class:`_query.Query` object or a class
    :class:`.Session` object, that is assumed to be within the context
    of an enclosing :class:`.BakedQuery` callable.
  kind: param
  key: 'param'
  arg_name: 'query_or_session'
  is_optional: False
=== detect
rest
=== compose rest
Return the :class:`_query.Query` object for use as a subquery.

This method should be used within the lambda callable being used
to generate a step of an enclosing :class:`.BakedQuery`.   The
parameter should normally be the :class:`_query.Query` object that
is passed to the lambda::

    sub_bq = self.bakery(lambda s: s.query(User.name))
    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

    main_bq = self.bakery(lambda s: s.query(Address))
    main_bq += lambda q: q.filter(sub_bq.to_query(q).exists())

In the case where the subquery is used in the first callable against
a :class:`.Session`, the :class:`.Session` is also accepted::

    sub_bq = self.bakery(lambda s: s.query(User.name))
    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

    main_bq = self.bakery(
        lambda s: s.query(Address.id, sub_bq.to_query(q).scalar_subquery())
    )

:param query_or_session: a :class:`_query.Query` object or a class
    :class:`.Session` object, that is assumed to be within the context
    of an enclosing :class:`.BakedQuery` callable.
