Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1713

Doctrine2 findBy( 'myFKAssociacionProperty' => array( 'foo' ) ); not working

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:

      Description

      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

        Activity

        Hide
        Benjamin Eberlei added a comment -

        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.

        Show
        Benjamin Eberlei added a comment - 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Pau Peris
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: