I'm trying to add a many-to-many relationship between two existing entities in Sylius (ShopUser and Taxon). I've followed the Doctrine documentation on this, and thought I had everything set up correctly, but I get the following error:
The association Sylius\Component\Core\Model\ShopUser#taxons refers to the owning side field Sylius\Component\Taxonomy\Model\Taxon#shop_users which does not exist.
Here's how I have things set up:
src/Sylius/Component/Taxonomy/Model/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/Component/Core/Model/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/Bundle/TaxonomyBundle/Resources/config/doctrine/model/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/Bundle/CoreBundle/Resources/config/doctrine/model/ShopUser.orm.xml:
<many-to-many field="taxons" mapped-by="shop_users" target-entity="Sylius\Component\Taxonomy\Model\Taxon" />
I've run the migration, and it successfully created the table 'sylius_taxon_shop_user' which has columns for taxon_id and shop_user_id.
I've done some reading on the many-to-many relationships, but can't seem to figure out why I'm getting the error.
EDIT:
the ShopUser model used to have this in the addTaxon code, which cauased an infinite loop:
$taxon->addShopUser($this); // Add this user to the taxon, as well (inverse side)
I've removed it now, but still get the same error.
2nd EDIT
I'd like to note that in commenting out the many-to-many tag in my ShopUser.orm.xml, the error changes and indicates that the mapping on the other side is also invalid:
The association Sylius\Component\Core\Model\Taxon#shop_users refers to the inverse side field Sylius\Component\Core\Model\ShopUser#taxons which does not exist.