Skip to content

Documentation for 'IN' with query builder is misleading #6597

Open
@gbirke

Description

@gbirke

The documentation for the query builder and building IN and NOT IN expression says

// Make sure that you do NOT use something similar to $qb->expr()->in('value', array('stringvalue')) as this will cause Doctrine to throw an Exception.
// Instead, use $qb->expr()->in('value', array('?1')) and bind your parameter to ?1 (see section above)

Relying on that comment I tried code like this:

$qb->where( $qb->expr()->in( 'd.status', [':statusA', ':statusB'] ) )
  ->addParameter( 'statusA', 'A' )
  ->addParameter( 'statusB', 'B' )

This lead to the error message Too many parameters: the query defines 0 parameters and you bound 2

When I specified the strings directly, the query worked as expected:

$qb->where( $qb->expr()->in( 'd.status', ['A', 'B'] ) )

Looking at the code in the expression builder it looks like my strings will be quoted correctly.

Is the comment in the documentation still relevant? Maybe it hints at a different use case (e.g. subqueries)?
I'm not sure how the text could be improved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions