Symfony fixtures getReference Missing reference 错误

Symfony fixtures getReference Missing reference error

我是 symfony 新手, 我有两个具有多对多关系的实体。 Action.phpEtablissement.php 我正在尝试从两个 .csv 文件(每个对象一个)填充我的数据库,其中包含教义固定装置。

我从 EtablissementFixtures.php 开始,其中我引用了每个 Etablissement $this->addReference($line[0], $etablissement); 以便我可以在我的其他 Fixture 中访问它。

问题是在我的第二个夹具 ActionFixture.php 中,.csv 包含一些在 Etablissement 的 .csv 中不存在的 ID。当我尝试 $this->getReference($line[0]) 我得到一个 Reference to "0010063N" does not exist 错误,我试图用 try/catch 块包围 getReference 行但是它不起作用,我想忽略该错误并继续执行代码。

希望我说清楚了,谢谢

欢迎来到 SO 论坛。

如果我对你的问题的理解正确,你正在寻找 hasReference 函数,你可以使用它来检查是否存在具有特定名称的引用:

$this->hasReference($line[0]);