G
G
gleb-mihalkov2015-09-19 00:28:11
Doctrine ORM
gleb-mihalkov, 2015-09-19 00:28:11

How to add entity property in Zend Framework 2, ORM Doctrine?

Good time of the day. The situation is the following. The module has an entity associated with a database table. It is required to add two persisted fields to it. But for some reason ORM does not store their values ​​in the database.
Did the following:
1) Added to the class declaration

/**
     * @ORM\Column(type="string", name="description", nullable=true)
     * @var string
     * @author gleb.mihalkov
     */
    private $description;

    /**
     * @ORM\Column(type="string", name="image", nullable=true)
     * @var string
     * @author gleb.mihalkov
     */
    private $image;

2) Added getters and setters:
/**
     * Returns stock's image url.
     * @return string
     * @author gleb.mihalkov
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Sets URL of stock's image.
     * @param string $url - Url of stock's image.
     * @author gleb.mihalkov
     */
    public function setImage($url)
    {
        $this->image = $url;
        return $this;
    }

    /**
     * Gets description of stock.
     * @return string
     * @author gleb.mihalkov
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Sets description of stock.
     * @param string $value - Value of new description.
     * @author gleb.mihalkov
     */
    public function setDescription($value)
    {
        $this->description = $value;
        return $value;
    }

3) Added input's, supplemented the form, view... In the controller method I checked through getters - the values ​​are assigned to the fields of the entity.
4) Added the table in the database with columns `image` varchar(255) and `description` varchar(255). Typos, checked, no.
And the following happens: ORM saves changes in the old fields of the entity, but not in the new ones. Tell me, please, what is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2015-09-19
@skobkin

Since you didn't show the full listing of the entity files, the only thing that comes to mind is that your entity mapping is, for example, in YAML, and for new fields you do it in annotations.
In general, try to validate the mapping. Also, try schema:create and see if your fields are in the resulting SQL. For example, like this:
orm:schema-tool:create --dump-sql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question