Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

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

@doctrinebot

Comment created by @beberlei:

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

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

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

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.