craue / CraueConfigBundle

Database-stored settings made available via a service for your Symfony project.
MIT License
173 stars 35 forks source link

Issues v2.3.0 and PR #50 #51

Closed Mopster closed 5 years ago

Mopster commented 5 years ago

I'm having issues with version 2.3.0 with PR #50 Installed this version and it broke my app. Getting the following error :

Class "Craue\ConfigBundle\Entity\Setting" sub class of "Craue\ConfigBundle\Entity\BaseSetting" is not a valid entity or mapped super class.

I had a custom Setting class, I had to shorten the name to 191 chars for indexing (multibyte).

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

class Setting extends \Craue\ConfigBundle\Entity\Setting
{
    /**
     * @ORM\Id
     * @ORM\Column(name="name", type="string", length=191, nullable=false, unique=true)
     * @Assert\NotBlank()
     */
    protected $name;
}

I did not have anything else in my config.yml or other code.

Checking the change and the readme, I changed my code to

use Craue\ConfigBundle\Entity\BaseSetting;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="Craue\ConfigBundle\Repository\SettingRepository")
 * @ORM\Table(name="config_setting")
 */
class Setting extends BaseSetting
{
    /**
     * @ORM\Id
     * @ORM\Column(name="name", type="string", length=191, nullable=false, unique=true)
     * @Assert\NotBlank()
     */
    protected $name;
}

and updated the config.yml to contain :

craue_config:
    entity_name: Tamago\DefaultBundle\Entity\Setting

Then made a DoctrineMigration to rename the craue_config_setting table to config_setting

But after all that, when getting a value, it returns null. I discovered the entity is not being hydrated correctly (value = null). Any changes to the value (setting a value) is not getting saved to the database.

Am I missing another setting somewhere ?

craue commented 5 years ago

When using a custom entity, you must provide a mapping for the value field as well. I wonder whether this worked before 2.3.0.

Mopster commented 5 years ago

@craue that looks to have fixed it, thanks!

It might've not correctly picked up my custom entity before. But I was storing values :-)