0

I try to save multiple translations like in this example, but I have an error.

here is entity

/**
 * @ORM\Entity
 * @Gedmo\TranslationEntity(class="BaseTranslation")
 * @ORM\Table(name="c_Base")
 */
class Base {

    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     */
    private $id;

    /**
     * Hexaid
     * @var string
     */
    private $hid;

    /**
     * @ORM\Column(type="string")
     * @GRID\Column(title="name")
     * @Gedmo\Translatable
     * @var string
     */
    private $name;

    /**
     * @ORM\Column(type="text", nullable=true)
     * @Gedmo\Translatable
     * @var string
     */
    private $description;

 /**
     * GRID\Column(title="translations",field="translations.content")
     * @ORM\OneToMany(
     *     targetEntity="BaseTranslation",
     *  mappedBy="object",
     *  cascade={"persist", "remove"}
     * )
     * @Assert\Valid(deep = true)
     */
    private $translations;

translation entity

/**
 * Entity\Translation\ProductTranslation.php

 * @ORM\Entity
 * @ORM\Table(name="c_base_translations",
 *   uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
 *     "locale", "object_id", "field"
 *   })}
 * )
 */
class BaseTranslation extends AbstractPersonalTranslation{
    /**
     * @ORM\ManyToOne(targetEntity="Base", inversedBy="translations")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $object;

    public function __construct($locale, $field, $value)
    {
        $this->setLocale($locale);
        $this->setField($field);
        $this->setContent($value);
    }

}

i try use multiple translations

  $em = $this->getDoctrine()->getManager();
        $repository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');

        $article = new Base();

        $article->setName('content en');

        $repository->translate($article, 'name', 'de', 'name de')
            ->translate($article, 'name', 'pl', 'name pl')

        ;

        $em->persist($article);
        $em->flush();

and get

Notice: Undefined index: foreignKey

[1] Symfony\Component\Debug\Exception\ContextErrorException: Notice: Undefined index: foreignKey
    at n/a
        in /home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 655

    at Symfony\Component\Debug\ErrorHandler->handleError('8', 'Undefined index: foreignKey', '/home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php', '655', array('name' => 'foreignKey'))
        in /home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 655

    at Doctrine\ORM\Mapping\ClassMetadataInfo->getReflectionProperty('foreignKey')
        in /home/grek/PhpstormProjects/welasy/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php line 80

    at Gedmo\Translatable\Entity\Repository\TranslationRepository->translate(object(Base), 'name', 'de', 'name de')
        in /home/grek/PhpstormProjects/welasy/vendor/Mea/CharterBundle/Controller/ResourcesController.php line 171

    at Mea\CharterBundle\Controller\ResourcesController->oneViewByHidAction('9888fff563a6a42', '2015;20')
        in  line 

    at call_user_func_array(array(object(ResourcesController), 'oneViewByHidAction'), array('9888fff563a6a42', '2015;20'))
        in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 3028

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 2990

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 3139

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 2383

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in /home/grek/PhpstormProjects/welasy/web/app_dev.php line 28
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
Developer
  • 2,731
  • 2
  • 41
  • 71
  • How you fixed this, bro? :) I have the same problem ;( [code identical to example https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations ] – Vlad Vlad Jul 14 '17 at 11:29

1 Answers1

0

add "@ORM\GeneratedValue" to Base

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
     */
    private $id;
Evgeniy Kuzmin
  • 2,384
  • 1
  • 19
  • 24
  • yes this was a litte bug but this is not reason. (i get part of code to show problem - bases dont have auto increment so i add id.) i update code in moment – Developer May 15 '15 at 20:23
  • I can only guess that the problem is related to "foreign key" of your tables, can you explore sql of tables and check do you have foreign key for tables relation? – Evgeniy Kuzmin May 15 '15 at 20:44
  • i create new topic about version configuration in this example i have older version - please se here http://stackoverflow.com/questions/30272455/translation-form-with-default-entity-translations-not-found – Developer May 16 '15 at 06:17
  • in here example - https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations dont have foreign key i dont know why – Developer May 16 '15 at 06:55