Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1908

Symfony 2 Doctrine join tables error

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux, Apache, mysql

      Description

      Hello developers of Doctrine. I appreiate your work on a such complicated project. So seems I'found a bug in Doctrine in generating SQL
      I had written this issue on Symfony forum but noone is answering, so maybe I've found the bug of Doctrine or FOSUserBundle
      I'm using Symfony 2.0.12, so I've installed as git submodules FOSUserBundle, created User Entity with one-to-one relationship with Company Entity, here goes the code:

      <?php
      
      namespace AV\TradeBundle\Entity;
      
      use FOS\UserBundle\Entity\User as BaseUser;
      use Doctrine\ORM\Mapping as ORM;
      
      /**
      
          @ORM\Entity
      
          @ORM\Table(name="fos_user")
          /
          class User extends BaseUser
          {
          /*
              @ORM\Id
              @ORM\Column(type="integer")
              @ORM\GeneratedValue(strategy="AUTO") */ protected $id;
      
          /**
              @var company *
              @ORM\OneToOne(targetEntity="Companies", mappedBy="user") * */ private $company;
      
          public function construct()
          {
          parent::construct();
          // your own logic
          }
      
          public function getCompany() {
          return $this->company;
          }
      
          public function setCompany($company) {
          $this->company = $company;
          }
          }
      

      and piece of Company Entity:

      <?php
      /**
      * @var user
      *
      * @ORM\OneToOne(targetEntity="user", inversedBy="company")
      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
      */
      private $user;
      

      When creating fixtures I'm using such method (all references are set, and I have checked for foreign keys in DB - everything is fine)
      $this->container->get('fos_user.user_manager')->createUser($user);
      When I'm trying to login I see such error:

      SQLSTATE[42S22]: Column not found: 1054 Unknown column 't46.id' in 'on clause'
      

      The whole SELECT statement that I found in logs sounds like this one:

      SELECT t0.username AS username1, t0.username_canonical AS username_canonical2, t0.email AS email3, t0.email_canonical AS email_canonical4, t0.enabled AS enabled5,
       t0.salt AS salt6, t0.password AS password7, t0.last_login AS last_login8, t0.locked AS locked9, t0.expired AS expired10, t0.expires_at AS expires_at11, 
      t0.confirmation_token AS confirmation_token12, t0.password_requested_at AS password_requested_at13, t0.roles AS roles14, t0.credentials_expired AS credentials_expired15,
       t0.credentials_expire_at AS credentials_expire_at16, t0.id AS id17, t18.id AS id19, t18.egrpou AS egrpou20, t18.business_form AS business_form21, t18.title AS title22, 
      t18.phone_code AS phone_code23, t18.phone_country_code AS phone_country_code24, t18.phone AS phone25, t18.fax_code AS fax_code26, 
      t18.fax_country_code AS fax_country_code27, t18.fax AS fax28, t18.website AS website29, t18.fio AS fio30, t18.birthday AS birthday31, t18.firm_created AS firm_created32, 
      t18.employees_count AS employees_count33, t18.logo AS logo34, t18.zip AS zip35, t18.street AS street36, t18.position AS position37, t18.thumb_logo AS thumb_logo38, 
      t18.description AS description39, t18.created_at AS created_at40, t18.email AS email41, t18.cities_id AS cities_id42, t18.regions_id AS regions_id43, t18.countries_id AS countries_id44,
       t18.user_id AS user_id45 FROM fos_user t0 LEFT JOIN companies t18 ON t18.user_id = t46.id WHERE t0.username_canonical = ? (["cfyzz"]) [] []
      

      Does anyone know why it's not t0 in join condition but t46?
      If needed I'll show my deps.lock, maybe such situation was already fixed, but I was googling for answer for several days - and nothing.
      Thanks in advance

        Activity

        Hide
        beberlei Benjamin Eberlei added a comment -

        Fixed formatting

        Show
        beberlei Benjamin Eberlei added a comment - Fixed formatting
        Hide
        beberlei Benjamin Eberlei added a comment -

        What version of Doctrine are you using? you can check in vendor/doctrine-orm/lib/Doctrine/ORM/Version.php

        Show
        beberlei Benjamin Eberlei added a comment - What version of Doctrine are you using? you can check in vendor/doctrine-orm/lib/Doctrine/ORM/Version.php
        Hide
        cfyzz Alex Koch added a comment -

        Thanks, Benjamin, for so quick answer.
        I've checked the file you mentioned - the version is "2.1.6"

        Show
        cfyzz Alex Koch added a comment - Thanks, Benjamin, for so quick answer. I've checked the file you mentioned - the version is "2.1.6"
        Hide
        beberlei Benjamin Eberlei added a comment -

        This was fixed in later versions.

        Show
        beberlei Benjamin Eberlei added a comment - This was fixed in later versions.

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            cfyzz Alex Koch
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: