Search code examples
symfonydoctrine-ormsylius

Customizing Models : Changes not being detected


I tried few things to customize a product, but got variants errors. So I decided to restart everything and follow the expected process to check if everything was alright.

So after a brand new blank installation of Sylius CE (like explained in the documentation), I followed the guide written on the documentation for customizing a model. But when I come to the migration step, this error is being raised : No changes detected in your mapping information.

I checked out the file path in the _sylius.yaml file, and everything is fine.

Is this intended since 2.0 release ? Am I missing an essential step ? Or is it just the documentation that is out of date, but I genually have no clue.

If it's not intended and we found no proper solution, I'll afterward raise an issue on the Github page.

Since it's a blank project, I've made no changes except the ones mentionned below.

Here's my Country file (Basically added the CountryiInterface and the flag attributes, like in the documentation) :

<?php

declare(strict_types=1);

namespace App\Entity\Addressing;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Addressing\Model\Country as BaseCountry;
use Sylius\Component\Addressing\Model\CountryInterface;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_country')]
class Country extends BaseCountry implements CountryInterface
{
    /** @ORM\Column(type="string", nullable=true) */
    private $flag;

    public function getFlag(): ?string
    {
        return $this->flag;
    }

    public function setFlag(string $flag): void
    {
        $this->flag = $flag;
    }
}

The dedicated section in the yaml file :

sylius_addressing:
    resources:
        address:
            classes:
                model: App\Entity\Addressing\Address
        country:
            classes:
                model: App\Entity\Addressing\Country
        province:
            classes:
                model: App\Entity\Addressing\Province
        zone:
            classes:
                model: App\Entity\Addressing\Zone
        zone_member:
            classes:
                model: App\Entity\Addressing\ZoneMember

I thought it was maybe due to the Model not coming from the Core, so I tried to edit the Product class which already had a Core importation (I've basically added an attribute) :

<?php

declare(strict_types=1);

namespace App\Entity\Product;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Product as BaseProduct;
use Sylius\Component\Product\Model\ProductTranslationInterface;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct
{
    /** @ORM\Column(type="integer", nullable=true) */
    private $capacity;

    public function getCapacity(): ?int
    {
        return $this->capacity;
    }

    public function setCapacity(int $capacity): void
    {
        $this->capacity = $capacity;
    }
    protected function createTranslation(): ProductTranslationInterface
    {
        return new ProductTranslation();
    }
}

And yet still no changes detected by Doctrine.


Solution

  • Found out that the ORM comments before the attribute declaration were messing all up : they're out of date.

    So here's what I did :

    #[ORM\Column(type:"integer", nullable: true)]
    private $capacity;
    

    And now Doctrine finally detects changes.

    Basically, Sylius' documentation is out of date regarding the ORM comments. I'll do an issue on the Github so it could be solved.