我正在尝试在Sylius(ShopUser和Taxon)中的两个现有实体之间添加多对多关系 . 我已经遵循了Doctrine文档,认为我已经正确设置了所有内容,但是我收到以下错误:

关联Sylius \ Component \ Core \ Model \ ShopUser#taxons是指不存在的拥有方字段Sylius \ Component \ Taxonomy \ Model \ Taxon#shop_users .

以下是我设置的方法:

SRC / Sylius /组件/分类/型号/ Taxon.php:

use Doctrine\Common\Collections\ArrayCollection;

class Taxon implements TaxonInterface {

    protected $shop_users;

    public function __construct() {
        $this->shop_users = new ArrayCollection();
    }

    public function getShopUsers() {
        return $this->shop_users;
    }

    public function addShopUser(ShopUser $user)
    {
        $user->addTaxon($this);
        $this->shop_users[] = $user;
    }

}

SRC / Sylius /组件/核心/型号/ ShopUser.php:

namespace Sylius\Component\Core\Model;

use Doctrine\Common\Collections\ArrayCollection;

class ShopUser extends BaseUser implements ShopUserInterface {

    protected $taxons;

    public function __construct() {
        $this->taxons = new ArrayCollection();
    }

    public function addTaxon(Taxon $taxon) {
        $this->taxons[] = $taxon; // Add the taxon to our collection of taxons available for this shop user
    }


    public function getTaxons() {
        return $this->taxons;
    }

}

SRC / Sylius /包/ TaxonomyBundle /资源/配置/教义/模型/ Taxon.orm.xml:

<many-to-many field="shop_users" inversed-by="taxons" target-entity="Sylius\Component\Core\Model\ShopUser">
    <join-table name="sylius_taxon_shop_user">
        <join-columns>
            <join-column name="taxon_id" referenced-column-name="id" />
        </join-columns>
        <inverse-join-columns>
            <join-column name="shop_user_id" referenced-column-name="id" />
        </inverse-join-columns>
    </join-table>
</many-to-many>

SRC / Sylius /包/ CoreBundle /资源/配置/教义/模型/ ShopUser.orm.xml:

<many-to-many field="taxons" mapped-by="shop_users" target-entity="Sylius\Component\Taxonomy\Model\Taxon" />

我已经运行了迁移,并成功创建了表'sylius_taxon_shop_user',其中包含taxon_id和shop_user_id的列 .

我已经对多对多关系做了一些阅读,但似乎无法弄清楚为什么我会收到错误 .

EDIT

ShopUser模型过去常常在addTaxon代码中使用它,这会导致无限循环:

$taxon->addShopUser($this); // Add this user to the taxon, as well (inverse side)

我现在删除了它,但仍然得到同样的错误 .

2nd EDIT

我想要注意的是,在我的ShopUser.orm.xml中注释掉多对多标记时,错误会发生变化并指示另一方的映射也是无效的:

关联Sylius \ Component \ Core \ Model \ Taxon#shop_users指的是不存在的反面字段Sylius \ Component \ Core \ Model \ ShopUser#taxons .