SonataAdminBundle: sonata_collection unable to add row via modal way

Environment

Windows 10 - Chrome 54

Sonata packages

sonata-project/admin-bundle 3.10.0
sonata-project/block-bundle 3.2.0
sonata-project/cache 1.0.7 sonata-project/core-bundle 3.1.1
sonata-project/datagrid-bundle 2.2
sonata-project/doctrine-extensions 1.0.2
sonata-project/doctrine-orm-admin-bundle 3.1.1 sonata-project/easy-extends-bundle 2.1.10 sonata-project/exporter 1.7.0 sonata-project/google-authenticator 1.0.2 sonata-project/user-bundle 3.2.0

Symfony packages

symfony/monolog-bundle 2.12.0 symfony/phpunit-bridge v2.8.14 symfony/polyfill-apcu v1.3 symfony/polyfill-intl-icu v1.3.0 symfony/polyfill-mbstring v1.3.0
symfony/polyfill-php54 v1.3.0 symfony/polyfill-php55 v1.3.0 symfony/polyfill-php56 v1.3.0 symfony/polyfill-php70 v1.3.0 symfony/polyfill-util v1.3.0 symfony/security-acl v2.8.0 symfony/swiftmailer-bundle v2.4.0 symfony/symfony v2.8.14

PHP version

PHP 5.5.12

Subject

In my admin I have a OneToMany defined as it:

/**
 * @ORM\OneToMany(targetEntity="Module", mappedBy="sequence", cascade={"persist", "remove"})
 */
 private $modules;

And the inversed side:

/**
 * @ORM\ManyToOne(targetEntity="ModuleSequence", inversedBy="modules", cascade={"persist"}, fetch="LAZY")
 * @ORM\JoinColumn(name="sequence_id", referencedColumnName="id")
 */
protected $sequence;

In my admin class I defined the ‘modules’ field as it:


->add('modules', 'sonata_type_collection',array(
       'by_reference' => false
 ))

Finally in the ModuleSequence Entity here’s the addModule method:

     /**
     * Add modules
     *
     * @param \AppBundle\Entity\Module $module
     * @return ModuleSequence
     */

    public function addModule(\AppBundle\Entity\Module $module)
    {
        $module->setSequence($this);
        $this->modules[] = $module;

        return $this;
    }

I have the “add” button, I get the modal, I fill it and validate. The Ajax request is sent into the profiler but no new row appear.

The ‘sequence_id’ is not set in the database and I don’t know why…

When I use the ‘inline’ & ‘table’ options, the id is well set.

I think there is a bug here.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 37 (26 by maintainers)

Most upvoted comments

Here is the doc that should be improved IMO

Ok, added to my todo list 😃

hello @greg0ire, I dig a little be more before editing the doc to understand what happens. The issue seams coming from the symfony form https://github.com/sonata-project/SonataAdminBundle/blob/3.13.0/Controller/CRUDController.php#L255 When the form populate the new object it doesn’t call setChildrend or 'addChild` so you can’t give the child the parent id. I don’t know that much symfony’s form component to understand if the issue is on symfony, sonata or doctrine. I continue…

Anyway, that a lot for your help 😃

If you want to repay me, please make a PR to document this (in the doctrine ORM bundle). @damienalexandre suggested it 4 years ago, but nobody reacted… would you be the awesome guy that breaks the circle?

So, I will keep this solution but, I think, we have pointed I real trouble with collection form type that need to be discuss by the Sonata Team 😉

Yeah… @sonata-project/contributors , thoughts on this?