sonata product Bundle mapping fault

0

I am installing Sonata Ecommerce. After a lot of mistakes, I've had this one that I can not solve:

[Mapping]  FAIL - The entity-class 'Application\Sonata\ProductBundle\Entity\ProductCollection' mapping is invalid:
* The association Application\Sonata\ProductBundle\Entity\ProductCollection#collection refers to the inverse side field Application\Sonata\ClassificationBundle\Entity\Collection#productCollection which does not exist.

Following the documentation in link , in the configuration from sonata_product I have:

sonata_product:
    products:
        # Prototype
        app.product:
            provider:             app.product.type  # Required
            manager:              app.product.manager  # Required
            variations:
                fields:           [] # Required
    class:
        product:              Application\Sonata\ProductBundle\Entity\Product
        package:              Application\Sonata\ProductBundle\Entity\Package
        product_category:     Application\Sonata\ProductBundle\Entity\ProductCategory
        product_collection:   Application\Sonata\ProductBundle\Entity\ProductCollection
        category:             Application\Sonata\ClassificationBundle\Entity\Category
        collection:           Application\Sonata\ClassificationBundle\Entity\Collection
        delivery:             Application\Sonata\ProductBundle\Entity\Delivery
        gallery:              Application\Sonata\MediaBundle\Entity\Gallery

app.product is a product that I created with the sonata:product:generate command.

I understand that it is necessary to define in the entity ClassificationBundle:Collection an inverse relation on ProductBundle:ProductCollection . But I do not find in the documentation any example about what kind of relationship. I have tried many-to-one and one-to-many , but still giving me the same error ...

    
asked by Jakala 29.03.2017 в 09:54
source

1 answer

0

Achieved: In the end it is a one-to-many. I have taken it for trial / error (I have not found anything related to it on the internet) I must have made a mistake in any of the previous attempts, I leave here the solution in case someone needs it.

I added the line

<one-to-many field="productCollection" mapped-by="collection" target-entity="Application\Sonata\ProductBundle\Entity\ProductCollection"/>

Once the file is edited, it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <!--
         This file has been generated by the EasyExtends bundle ( https://sonata-project.org/easy-extends )

         References :
            xsd                  : https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd
            xml mapping          : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/xml-mapping/en
            association mapping  : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en
    -->
    <entity
        name="Application\Sonata\ClassificationBundle\Entity\Collection"
        table="classification__collection"
        repository-class="Doctrine\ORM\EntityRepository">

        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>
        <one-to-many field="productCollection" mapped-by="collection" target-entity="Application\Sonata\ProductBundle\Entity\ProductCollection"/>
    </entity>
</doctrine-mapping>
    
answered by 30.03.2017 в 14:08