我在 2 个条目中映射了多对多,但我有这个错误:
无法确定类"AppBundle\Entity\"中的属性"技能"的访问类型。
代码实体公司:
/**
* @var SkillInterface[]
*
* @ORMManyToMany(targetEntity="Skill", inversedBy="companys", cascade={"all"})
* @ORMJoinTable(name="companys_has_skills",
* joinColumns={
* @ORMJoinColumn(name="company_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORMJoinColumn(name="skill_id", referencedColumnName="id")
* }
* )
* @AssertCount(min = 1)
*/
private $skills;
public function __construct()
{
$this->skills = new ArrayCollection();
}
/**
* Add skills.
*
* @param SkillInterface $skills
*
* @return Company
*/
public function addSkills(AppBundleEntitySkill $skills)
{
$this->skills[] = $skills;
return $this;
}
/**
* Remove skills.
*
* @param SkillInterface $skills
*/
public function removeSkills(AppBundleEntitySkill $skills)
{
$this->skills->removeElement($skills);
}
/**
* Get skills.
*
* @return Collection
*/
public function getSkills()
{
return $this->skills;
}
代码实体技能:
/**
* @var Collection
*
* @ORMManyToMany(targetEntity="Company", mappedBy="skills")
*/
private $companys;
/**
* Constructor.
*/
public function __construct()
{
$this->companys = new ArrayCollection();
}
/**
* Add company.
*
* @param AppBundleEntityCompany $company
*
* @return Skill
*/
public function addCompany(AppBundleEntityCompany $company)
{
$this->companys[] = $company;
return $this;
}
/**
* Remove company.
*
* @param AppBundleEntityCompany $company
*/
public function removeCompany(AppBundleEntityCompany $company)
{
$this->companys->removeElement($company);
}
/**
* Get companys.
*
* @return DoctrineCommonCollectionsCollection
*/
public function getCompanys()
{
return $this->companys;
}
现在我在 2 个实体中制作了删除、添加和获取变量的功能,但我也有错误,我初始化为 arrayCollection
函数名称应该addSkill
和removeSkill
而不s
。