Giter Club home page Giter Club logo

Comments (6)

zhil avatar zhil commented on June 5, 2024

Looks like its still an issue.

I have entity Comment and Comments Thread

class CommentsThread
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;
    /**
     * @var integer $commentsCounter
     *
     * @ORM\Column(name="comments_counter", type="integer", nullable=false)
     */
    protected $commentsCounter = 0;
    /**
     * @var boolean $isCommentsEnabled
     *
     * @ORM\Column(name="is_comments_enabled", type="boolean", nullable=false)
     */
    protected $isCommentsEnabled = true;
    /**
     * @ORM\OneToMany(targetEntity="ACME\BUNDLE\Entity\Comment", mappedBy="commentsThread", cascade={"all"},orphanRemoval=true)
     */
    public $comments;

I show related comments in commentsThread admin with code like

class CommentsThreadAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('GeneralSection')
                
                ->add('comments','sonata_type_collection', array('by_reference' => false), array('edit' => 'inline','inline' => 'table','targetEntity'=>'Vido\CoreBundle\Entity\Comment'))
                ->add('isCommentsEnabled','checkbox',array('required'=>false))
            ->end()
        ;
    }

and related commentAdmin

class CommentAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('GeneralSection')
                ->add("createdUser")
                ->add("createdAt")
                ->add('body',null, array('required'=>true))
            ->end()
        ;
    }

Update function works great :)
But when I select checkbox near some comment I got error

[1/2] PDOException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`articles`, CONSTRAINT `FK_BFDD3168A16B7634` FOREIGN KEY (`comments_thread_id`) REFERENCES `comments_threads` (`id`)) 

    at PDOStatement ->execute (array('2'))
    in \vendor\doctrine-dbal\lib\Doctrine\DBAL\Connection.php at line 709  
    at Connection ->executeUpdate ('DELETE FROM comments_threads WHERE id = ?', array('2'))
    in \vendor\doctrine-dbal\lib\Doctrine\DBAL\Connection.php at line 432  -+

So its actually try to delete commentThread itself instead of checked for deletion comment :(

from sonataadminbundle.

rande avatar rande commented on June 5, 2024

This issue can be solve by using the related entity manager to delete/save/update the related object

from sonataadminbundle.

zhil avatar zhil commented on June 5, 2024

thanks for suggestion, but I dont get you though :(

Lets say, I have
Article with sonata_type_admin item of CommentsThread which have sonata_type_collection with Comments.
Near each comment there are checkbox for comments deletion.
When I check checkbox near comment entity - CommentsThread delete query created, which is wrong.
It seems to be a bug.

from sonataadminbundle.

rande avatar rande commented on June 5, 2024

The comment is about how to implement the fix in the AdminBundle.

from sonataadminbundle.

valqk avatar valqk commented on June 5, 2024

maybe Zhil has solved his issue but for those that are wondering:

      /**
      * {@inheritdoc}
      */
     public function setGalleryHasMedias($galleryHasMedias)
     {
          foreach ($galleryHasMedias as $galleryHasMedia) {
              $galleryHasMedia->setGallery($this);
          }

          $this->galleryHasMedias = $galleryHasMedias;
     }

this is the snippet you need. You must implement the setRelated in your parent Entity like this and it starts working.

from sonataadminbundle.

core23 avatar core23 commented on June 5, 2024

@rande Can you check this old issue?

from sonataadminbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.