私はSymfonyとDoctrineを使い始めており、多対多の関係に問題があります。 次の2つのエンティティが多対多に関連付けられています。私のコントローラでsymfony3 doctrine selectに多対多のカラムが見つかりません
AppBundle /エンティティ/ User.php
/**
* @ORM\ManyToMany(targetEntity="Team", mappedBy="user", cascade={"all"})
*
*/
private $team;
public function __construct()
{
parent::__construct();
$this->team = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add team
*
* @param \AppBundle\Entity\Team $team
*
* @return User
*/
public function addTeam(\AppBundle\Entity\Team $team)
{
$this->team[] = $team;
return $this;
}
/**
* Remove team
*
* @param \AppBundle\Entity\Team $team
*/
public function removeTeam(\AppBundle\Entity\Team $team)
{
$this->team->removeElement($team);
}
/**
* Get team
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTeam()
{
return $this->team;
}
AppBundle /エンティティ/ Team.php
/**
* @ORM\ManyToMany(targetEntity="User", inversedBy="team", cascade={"persist"})
* @ORM\JoinTable(name="user_team")
*/
private $user;
public function __construct()
{
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add user
*
* @param \AppBundle\Entity\User $user
*
* @return Team
*/
public function addUser(\AppBundle\Entity\User $user)
{
$this->user[] = $user;
return $this;
}
/**
* Remove user
*
* @param \AppBundle\Entity\User $user
*/
public function removeUser(\AppBundle\Entity\User $user)
{
$this->user->removeElement($user);
}
/**
* Get user
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUser()
{
return $this->user;
}
、私は次のコードを持っている:
AppBundle /コントローラ/ DefaultController.php
$em = $this->getDoctrine()->getManager();
$em->getRepository('AppBundle:Team')->findBy(array('user'=>$usr));
そして私は、TE次のエラーを持っている:
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.description AS description_3, t0.active AS active_4, t0.date_add AS date_add_5, t0.date_modified AS date_modified_6 FROM team t0 WHERE user_team.user_id = ?' with params [2]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_team.user_id' in 'where clause' 500 Internal Server Error - InvalidFieldNameException
私は間違って何をやっているしていますか?
この関係は? コントローラーは? 多分すべてですか?
ありがとうございました:)
はどういうわけかDoctrineは全体' JOIN'が欠落しているようなものに
:
また、この注釈を修正してみてください')そしてdoctrineがあなたのスキーマをどうにか更新したいかどうかを調べてください:' php bin/console doctrine:schema:update --dump-sql'。 – ccKep
テーブルuser_teamはどのように見えますか? – kormik
ありがとうございました:) – RL83