Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 2.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Join columns can't be quoted like columns using name="`quoted`". Using annotation driver.

      /**
       * @ORM\Table(
       *      name="`category`",
       *      indexes={
       *          @ORM\Index(
       *              name="fk_category_parentId",
       *              columns={"parentId"}
       *          )
       *      },
       *      uniqueConstraints={
       *          @ORM\UniqueConstraint(
       *              name="uq_category_nameParentId",
       *              columns={"name", "parentId"}
       *          )
       *      }
       * )
       */
      class Category
      {
          /**
           * @ORM\Id
           * @ORM\Column(type="smallint", name="`id`")
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          protected $id;
      
          /**
           * @ORM\Column(type="smallint", name="`parentId`", nullable=true)
           */
          protected $parentId;
      
          /**
           * @ORM\Column(type="string", length=50, name="`name`")
           */
          protected $name;
      
          /**
           * @ORM\ManyToOne(targetEntity="Category", inversedBy="categories")
           * @ORM\JoinColumn(name="parentId", referencedColumnName="id", onDelete="CASCADE", onUpdate="NO ACTION")
           */
          protected $category;
      }
      
      ... 
      
      
      public function load(ObjectManager $manager)
          {
              $parent = new Category();
              $parent->setName('parent');
              $manager->persist($parent);
              $manager->flush();
      
              $child = new Category();
              $child->setName('parent');
              $child->setParentId($parent->getId());
              $child->setCategory($parent);
      
              $manager->persist($child);
              $manager->flush();
      }
      

      Result: Invalid parameter number: number of bound variables does not match number of tokens

        Activity

        Hide
        Fabio B. Silva added a comment -

        code format

        Show
        Fabio B. Silva added a comment - code format
        Show
        Fabio B. Silva added a comment - Fixed by : https://github.com/doctrine/doctrine2/commit/cb72219b118c158c9b5344c4b81ff2b1a9149ab0
        Hide
        Marc Easen added a comment -

        When inserting into an entity which has quoted columns and unquoted JoinColumn the generated SQL includes the correct number of parameters but the incorrect columns names and bind parameters:

        INSERT INTO `table` (`c1`, c1) VALUES (?, ?)

        Show
        Marc Easen added a comment - When inserting into an entity which has quoted columns and unquoted JoinColumn the generated SQL includes the correct number of parameters but the incorrect columns names and bind parameters: INSERT INTO `table` (`c1`, c1) VALUES (?, ?)
        Show
        Marc Easen added a comment - See https://github.com/doctrine/doctrine2/pull/390
        Hide
        Fabio B. Silva added a comment -

        Hi Marc,

        Could you attach your entities or a test case please ?

        Thanks

        Show
        Fabio B. Silva added a comment - Hi Marc, Could you attach your entities or a test case please ? Thanks
        Hide
        Fabio B. Silva added a comment -

        Marc, why do you need to quoted columns and unquoted join column ?

        For sure duplicated columns is a problem, but your use case does not make sense for me..

        Show
        Fabio B. Silva added a comment - Marc, why do you need to quoted columns and unquoted join column ? For sure duplicated columns is a problem, but your use case does not make sense for me..
        Hide
        Fabio B. Silva added a comment -

        More details about the related problem : https://github.com/doctrine/doctrine2/pull/390

        Show
        Fabio B. Silva added a comment - More details about the related problem : https://github.com/doctrine/doctrine2/pull/390

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Marc Easen
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: