Doctrine 1
  1. Doctrine 1
  2. DC-377

Cannot delete a taggable record (Taggable Extension)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: Extensions
    • Labels:
      None
    • Environment:
      PHP 5.3.1, Mac OS X (10.6), MySQL 5.0.86, Symfony 1.4.1

      Description

      With Taggable extension, when I try to delete a record using Taggable, I get this exception :

      SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`sf_sandbox/article_taggable_tag`, CONSTRAINT `article_taggable_tag_id_article_id` FOREIGN KEY (`id`) REFERENCES `article` (`id`))

      If I check the sql queries generated by Doctrine, there are not "onDelete CASCADE" for one of relation added by Taggable extension.

      I have write some test cases for reproduce this bug (checking if relation has a property onDelete setted to CASCADE) but I can't reproduce the thrown exception in test case because sqlite omits queries with constraint. Also, I found how to fix this bug.

      The fix and test cases are available in the file attached to this ticket.

        Activity

        Fabien Pennequin created issue -
        Jonathan H. Wage made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Hide
        Jason added a comment -

        Hi Jon-

        Where can I find this fix?

        http://svn.doctrine-project.org/extensions/Taggable/branches/1.2-1.0 (the link referenced from the docs at http://www.doctrine-project.org/extension/Taggable) doesn't have this fix.

        Show
        Jason added a comment - Hi Jon- Where can I find this fix? http://svn.doctrine-project.org/extensions/Taggable/branches/1.2-1.0 (the link referenced from the docs at http://www.doctrine-project.org/extension/Taggable ) doesn't have this fix.
        Hide
        Jason added a comment -

        Sorry, it appears the patch attached above is in SVN, however this is still broken.

        With Doctrine 1.2.2 sandbox configured to work with MySQL 5.x database on 5.2.10, using the following schema

        {{
        BlogPost:
        actAs: [Taggable]
        columns:
        title:
        type: string(255)
        notnull: true
        description:
        type: string(255)
        notnull: true
        }}

        the CASCADE in the constraints for the table being applied the Taggable behavior are still not being applied (see first constraint below)

        {{
        CREATE TABLE `blog_post_taggable_tag` (
        `id` bigint(20) NOT NULL DEFAULT '0',
        `tag_id` bigint(20) NOT NULL DEFAULT '0',
        PRIMARY KEY (`id`,`tag_id`),
        KEY `blog_post_taggable_tag_tag_id_taggable_tag_id` (`tag_id`),
        CONSTRAINT `blog_post_taggable_tag_id_blog_post_id` FOREIGN KEY (`id`) REFERENCES `blog_post` (`id`),
        CONSTRAINT `blog_post_taggable_tag_tag_id_taggable_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `taggable_tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
        }}

        Show
        Jason added a comment - Sorry, it appears the patch attached above is in SVN, however this is still broken. With Doctrine 1.2.2 sandbox configured to work with MySQL 5.x database on 5.2.10, using the following schema {{ BlogPost: actAs: [Taggable] columns: title: type: string(255) notnull: true description: type: string(255) notnull: true }} the CASCADE in the constraints for the table being applied the Taggable behavior are still not being applied (see first constraint below) {{ CREATE TABLE `blog_post_taggable_tag` ( `id` bigint(20) NOT NULL DEFAULT '0', `tag_id` bigint(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`,`tag_id`), KEY `blog_post_taggable_tag_tag_id_taggable_tag_id` (`tag_id`), CONSTRAINT `blog_post_taggable_tag_id_blog_post_id` FOREIGN KEY (`id`) REFERENCES `blog_post` (`id`), CONSTRAINT `blog_post_taggable_tag_tag_id_taggable_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `taggable_tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | }}
        Hide
        Malcolm Hall added a comment -

        I use Doctrine v1.2.4 and created a fix for this problem, change the _options array initialization in Taggable.php to this:

        protected $_options = array(
        'builderOptions' => array(),
        'tagField' => null,
        'cascadeDelete' => true
        );

        This works because parent::buildRelation() calls the buildLocalRelation() method in Generator.php which looks for the cascadeDelete and if true then it adds the necessary CASCADE params, as you can see below:

        public function buildLocalRelation($alias = null)
        {
        ...
        if (isset($this->_options['cascadeDelete']) && $this->_options['cascadeDelete'] && ! $this->_options['appLevelDelete'])

        { $options['onDelete'] = 'CASCADE'; $options['onUpdate'] = 'CASCADE'; }

        ...

        Now both parts of the taggable relation get the cascade on delete feature. So if you delete a tag OR you delete a post, the row in the taggable_tag table gets deleted too.

        Show
        Malcolm Hall added a comment - I use Doctrine v1.2.4 and created a fix for this problem, change the _options array initialization in Taggable.php to this: protected $_options = array( 'builderOptions' => array(), 'tagField' => null, 'cascadeDelete' => true ); This works because parent::buildRelation() calls the buildLocalRelation() method in Generator.php which looks for the cascadeDelete and if true then it adds the necessary CASCADE params, as you can see below: public function buildLocalRelation($alias = null) { ... if (isset($this->_options ['cascadeDelete'] ) && $this->_options ['cascadeDelete'] && ! $this->_options ['appLevelDelete'] ) { $options['onDelete'] = 'CASCADE'; $options['onUpdate'] = 'CASCADE'; } ... Now both parts of the taggable relation get the cascade on delete feature. So if you delete a tag OR you delete a post, the row in the taggable_tag table gets deleted too.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-377, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Fabien Pennequin
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: