B
B
backEndDeveloper2019-03-14 11:35:17
symfony
backEndDeveloper, 2019-03-14 11:35:17

OneToOne connection does not work (Doctrine v2.5.14). What could be the problem?

There are 2 entities

/**
 * Catalog
 *
 * @ORM\Table(name="catalog", indexes={@ORM\Index(name="position_idx", columns={"position"})})
 * @DoctrineAssert\UniqueEntity(fields="url", message="URL должен быть уникальным")
 * @ORM\Entity
 */
class Catalog
{
    /**
     * @var CatalogTemplate
     *
     * @ORM\OneToOne(targetEntity="CatalogTemplate", mappedBy="catalog", cascade={"persist"})
     **/
    private $template;
}

and
/**
 * CatalogTemplate
 * @ORM\Entity
 * @ORM\Table(name="catalog_template")
 */
class CatalogTemplate
{
/**
     * @ORM\OneToOne(targetEntity="Catalog", inversedBy="template")
     * @ORM\JoinColumn(name="catalog_id", referencedColumnName="id")
     */
    private $catalog;
}

In a DB everything was updated there were communications, tables, fields.
Manually created 1 record in the tables, but when I write it
$catalog->getTemplate()->getId();
gives an error
Call to a member function setValue() on null
It is interesting that the same code works on the local machine, on the server it gives an error. The versions of the doctrine are identical.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
backEndDeveloper, 2019-03-14
@backEndDeveloper

MAIN rule when updating the database, do not forget to add --env=prod
for the command php bin/console doctrine:cache:clear-metadata =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question