我的目标是通过影响者 ID 获得所有应用程序。
我试过了:
public function findApplicationByInfluencer($value): ?Application
{
return $this->createQueryBuilder('a')
->where('a.influencerId = :value')
->setParameter('value', $value)
->getQuery()
->getResult();
}
但是得到这个错误:“ [Semantical Error] line 0, col 47 near 'influencerId': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected. ”
我不明白,也不知道如何解决。我从实体中删除了一些不影响我的问题的代码。
申请实体:
/**
* @ORM\Entity(repositoryClass=ApplicationRepository::class)
*/
class Application
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity=Influencer::class, inversedBy="applications")
*/
private $influencerId;
public function __construct()
{
$this->influencerId = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Influencer[]
*/
public function getInfluencerId(): Collection
{
return $this->influencerId;
}
public function addInfluencerId(Influencer $influencerId): self
{
if (!$this->influencerId->contains($influencerId)) {
$this->influencerId[] = $influencerId;
}
return $this;
}
public function removeInfluencerId(Influencer $influencerId): self
{
$this->influencerId->removeElement($influencerId);
return $this;
}
}
影响者实体:
/**
* @ORM\Entity(repositoryClass=InfluencerRepository::class)
* @UniqueEntity("username", message="Ce pseudo est déjà utilisé")
* @Vich\Uploadable
*/
class Influencer
{
const SERVER_PATH_TO_IMAGE_FOLDER = '/public/uploads';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity=Application::class, mappedBy="influencerId")
*/
private $applications;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
public function __construct()
{
$this->applications = new ArrayCollection();
$this->brandId = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Application[]
*/
public function getApplications(): Collection
{
return $this->applications;
}
public function addApplication(Application $application): self
{
if (!$this->applications->contains($application)) {
$this->applications[] = $application;
$application->addInfluencerId($this);
}
return $this;
}
public function removeApplication(Application $application): self
{
if ($this->applications->removeElement($application)) {
$application->removeInfluencerId($this);
}
return $this;
}
}