0

I add SEO data to my entity following this article http://symfony.com/doc/current/cmf/bundles/seo/seo_aware.html.

    class Provider implements SeoAwareInterface
    {
        /**
         * @var SeoMetadataInterface
         *
         * @ORM\OneToOne(targetEntity="Symfony\Cmf\Bundle\SeoBundle\Model\SeoMetadata", cascade={"persist","remove"})
         * @ORM\JoinColumn(name="seo_metadata_id", referencedColumnName="id")
         */
        protected $seoMetadata;
    }

I use SonataAdmin to edit Provider entity and I use special form type for seoMetadata property - SeoMetadataType (http://symfony.com/doc/current/cmf/bundles/seo/seo_aware.html#form-type)

protected function configureFormFields(FormMapper $form)
{
    $form
        // some entity related fields
        ->with('form.provider.seo_group_title', [
            'class' => 'col-md-4',
        ])
            ->add('seoMetadata', SeoMetadataType::class, [], [
                'generic_metadata' => false,
            ])
        ->end()
    ;
}

The problem is next - everytime I edit Provider entity I get new record of SeoMetadata.

I've debug updating process and before persist and flush operation I have proxy of SeoMetadata in $seoMetadata property with existed id, but after persist and flush operations I see proxy with new id and new record in table.

Anybody have idea whats wrong?

1 Answers1

0

We do have some ORM examples, but do not fully support it atm. But can you reproduce your issue of persistence only by adding some code here: https://github.com/symfony-cmf/seo-bundle/blob/master/tests/Functional/Doctrine/Orm/SeoMetadataTest.php Simply do a PR and i will try to fix it. But it can also be, that the issue is in sonata or in the forms.