使用错误的 table 别名生成查询的原则 - Symfony 5
Doctrine generating query with wrong table alias - Symfony 5
我正在尝试在我的数据库中插入一个用户,并在此之前生成学说:
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.first_name AS first_name_3, t0.username AS username_4, t0.password AS password_5, t0.aRoles AS aRoles_6, t0.create_date AS create_date_7, t8.id AS id_9, t8.name AS name_10, t8.siren AS siren_11, t8.social_network_list AS social_network_list_12, t8.sponso AS sponso_13, t8.created_date AS created_date_14, t8.user_id AS user_id_15 FROM user t0 LEFT JOIN company t8 ON t8.user_id = t16.id WHERE t0.username = ?' with params ["test@gmail.com"]:
出现以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't16.id' in 'on clause'
Doctrine 创建了一个别名 "t16" 但好的别名是 "t0"
在我的控制器中,我使用一个表单来管理用户注册。
我的用户实体在这里:
**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(
* fields={"username"},
* message="Le compte est existant !"
* )
*/
class User implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email()
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(min="8", minMessage="Votre mot de passe doit faire au minimum 8 caractères")
*/
private $password;
/**
* @Assert\EqualTo(propertyPath="password", message="Les mots de passes ne sont pas identiques")
*/
public $confirm_password;
/**
* @var array
*
* @ORM\Column(name="aRoles", type="array", length=400, nullable=false)
*/
private $aroles;
/**
* @ORM\Column(type="datetime")
*/
private $createDate;
/**
* @ORM\OneToOne(targetEntity=Company::class, mappedBy="user")
*/
private $company;
公司实体:
/**
* @ORM\Entity(repositoryClass=CompanyRepository::class)
*/
class Company
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $siren;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $socialNetworkList;
/**
* @ORM\Column(type="boolean")
*/
private $sponso;
/**
* @ORM\Column(type="datetime")
*/
private $createdDate;
/**
* @ORM\OneToOne(targetEntity=user::class, inversedBy="company")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
感谢您的回答
可能与某些配置错误有关。将映射更改为:
用户
/**
* @ORM\OneToOne(targetEntity="Company", mappedBy="user")
*/
private $company;
公司(见用户中的上限)
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="company")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
我正在尝试在我的数据库中插入一个用户,并在此之前生成学说:
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.first_name AS first_name_3, t0.username AS username_4, t0.password AS password_5, t0.aRoles AS aRoles_6, t0.create_date AS create_date_7, t8.id AS id_9, t8.name AS name_10, t8.siren AS siren_11, t8.social_network_list AS social_network_list_12, t8.sponso AS sponso_13, t8.created_date AS created_date_14, t8.user_id AS user_id_15 FROM user t0 LEFT JOIN company t8 ON t8.user_id = t16.id WHERE t0.username = ?' with params ["test@gmail.com"]:
出现以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't16.id' in 'on clause'
Doctrine 创建了一个别名 "t16" 但好的别名是 "t0"
在我的控制器中,我使用一个表单来管理用户注册。
我的用户实体在这里:
**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(
* fields={"username"},
* message="Le compte est existant !"
* )
*/
class User implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email()
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(min="8", minMessage="Votre mot de passe doit faire au minimum 8 caractères")
*/
private $password;
/**
* @Assert\EqualTo(propertyPath="password", message="Les mots de passes ne sont pas identiques")
*/
public $confirm_password;
/**
* @var array
*
* @ORM\Column(name="aRoles", type="array", length=400, nullable=false)
*/
private $aroles;
/**
* @ORM\Column(type="datetime")
*/
private $createDate;
/**
* @ORM\OneToOne(targetEntity=Company::class, mappedBy="user")
*/
private $company;
公司实体:
/**
* @ORM\Entity(repositoryClass=CompanyRepository::class)
*/
class Company
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $siren;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $socialNetworkList;
/**
* @ORM\Column(type="boolean")
*/
private $sponso;
/**
* @ORM\Column(type="datetime")
*/
private $createdDate;
/**
* @ORM\OneToOne(targetEntity=user::class, inversedBy="company")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
感谢您的回答
可能与某些配置错误有关。将映射更改为:
用户
/**
* @ORM\OneToOne(targetEntity="Company", mappedBy="user")
*/
private $company;
公司(见用户中的上限)
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="company")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;