こんにちは、エンティティ onetoMany と ManyToOne を完全に正常に設定しました。セッターとゲッターを生成し、ユーザー エンティティでこのメソッドを作成しました。
ユーザー エンティティ:
/**
* @ORM\OneToMany(targetEntity="TB\RequestsBundle\Entity\Requests", mappedBy="followeeuser")
*/
protected $followees;
リクエストエンティティ:
/**
* @ORM\ManyToOne(targetEntity="TB\UserBundle\Entity\User", inversedBy="followees")
* @ORM\JoinColumn(name="followee_id", referencedColumnName="id", nullable=false)
*/
protected $followeeuser;
そして、私が独自のカスタムクエリを使用するとうまくいきます...しかし、symfonyから生成されたこの関数を使用する方法がわかりません:
public function addFollowee(\TB\UserBundle\Entity\User $followee)
{
$this->followees[] = $followee;
}
そこに何を渡すかわかりません...最初に小枝からのユーザーのIDに基づいてユーザーオブジェクトを取得しようとしました...うまくいきましたが、エラーが発生しました:
$user->addFollowee($userRepository->find($target_user_id));
Found entity of type TB\UserBundle\Entity\User on association TB\UserBundle\Entity\User#followees, but expecting TB\RequestsBundle\Entity\Requests