DDC-1713: Doctrine2 findBy( 'myFKAssociacionProperty' => array( 'foo' ) ); not working #2156

Closed
opened 2026-01-22 13:42:53 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 17, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sibok:

A Foo Entity has the following association:

/****
* @ORM\OneToOne(targetEntity="Domain", inversedBy="WebSite")
* @ORM\JoinColumn(name="domain", referencedColumnName="domain", nullable=false)
*/
private $domain;

which fails to query by the following method ( note the array of values in the findBy() ):

$this->doctrine->getEntityManager( 'default' )->getRepository( '\myVendor\myBundle\Entity\myEntity' )->findBy( array( 'myProperty' => array( 'myValue' ) ) );

Curioously that does work ( note it has no values array ):

$this->doctrine->getEntityManager( 'default' )->getRepository( '\myVendor\myBundle\Entity\myEntity' )->findBy( array( 'myProperty' => 'myValue' ) );

The error i get on the first query is:

Notice: Undefined index: myProperty in /home/developer/public_html/myProject/vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1324

Finally as workaround i went with:

$em->createQuery('SELECT uws FROM MyProject\Model\WebSite ws JOIN ws.domain WHERE ws.domain = (?) ');
//Here passed the array of parameters

and had no problems

Originally created by @doctrinebot on GitHub (Mar 17, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sibok: A Foo Entity has the following association: ``` /**** * @ORM\OneToOne(targetEntity="Domain", inversedBy="WebSite") * @ORM\JoinColumn(name="domain", referencedColumnName="domain", nullable=false) */ private $domain; ``` which fails to query by the following method ( note the array of values in the findBy() ): $this->doctrine->getEntityManager( 'default' )->getRepository( '\myVendor\myBundle\Entity\myEntity' )->findBy( array( 'myProperty' => array( 'myValue' ) ) ); Curioously that does work ( note it has no values array ): $this->doctrine->getEntityManager( 'default' )->getRepository( '\myVendor\myBundle\Entity\myEntity' )->findBy( array( 'myProperty' => 'myValue' ) ); The error i get on the first query is: Notice: Undefined index: myProperty in /home/developer/public_html/myProject/vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1324 Finally as workaround i went with: $em->createQuery('SELECT uws FROM MyProject\Model\WebSite ws JOIN ws.domain WHERE ws.domain = (?) '); //Here passed the array of parameters and had no problems
admin added the Bug label 2026-01-22 13:42:53 +01:00
admin closed this issue 2026-01-22 13:42:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 27, 2012):

Comment created by @beberlei:

This works with Doctrine 2.2.*, see test 2e79637be8

You can pass an array of values and it will create a query:

SELECT * FROM Entity WHERE association_id IN (?) and use Doctrine\DBAL\Connection::PARAM_INT_ARRAY to build the query.

@doctrinebot commented on GitHub (May 27, 2012): Comment created by @beberlei: This works with Doctrine 2.2.*, see test https://github.com/doctrine/doctrine2/commit/2e79637be83449f9558e3f1eb326b582299a50eb You can pass an array of values and it will create a query: SELECT \* FROM Entity WHERE association_id IN (?) and use Doctrine\DBAL\Connection::PARAM_INT_ARRAY to build the query.
Author
Owner

@doctrinebot commented on GitHub (May 27, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (May 27, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2156