Doctrine 1
  1. Doctrine 1
  2. DC-189

When applying changes to n:n relations that contain partially same data DELET is not fired

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2.0-BETA1, 1.2.0-BETA2
    • Fix Version/s: 1.2.0-RC1
    • Component/s: Relations
    • Labels:
      None
    • Environment:
      Error introduced in revision 6611

      Description

      When changing n:n relations in a way that the new dataset contains relations that were present in the previous state (as in adding a relation to existing ones) DELETE is not fired before insert is done. In the example below I simply reapply an existing relation. This is done by Record::synchronizeWithArray().

      Result:

      Doctrine_Connection_Mysql_Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4-14' for key 'PRIMARY'

      SQL Query pre r6611:
      6 Query START TRANSACTION
      6 Query UPDATE `structure` SET `user_create_id` = NULL, `user_modify_id` = NULL, `updated_at` = '2009-11-04 23:38:02' WHERE `id` = '4'
      6 Query DELETE FROM `structure_category` WHERE (`structure_id` = '4')
      6 Query INSERT INTO `structure_category` (`category_id`, `structure_id`) VALUES ('5', '4')
      6 Query COMMIT

      SQL QUERY with r6611:
      5 Query START TRANSACTION
      5 Query UPDATE `structure` SET `user_create_id` = NULL, `user_modify_id` = NULL, `updated_at` = '2009-11-04 23:36:33' WHERE `id` = '4'
      5 Query INSERT INTO `structure_category` (`category_id`, `structure_id`) VALUES ('5', '4')
      5 Query ROLLBACK

        Activity

        Hide
        Jaanus Heeringson added a comment -

        Added 1.2.0-BETA2

        Show
        Jaanus Heeringson added a comment - Added 1.2.0-BETA2
        Hide
        Jonathan H. Wage added a comment -

        Can you show the code you're using? a test case of some sort. It is really hard to fix the problem with so little information

        Show
        Jonathan H. Wage added a comment - Can you show the code you're using? a test case of some sort. It is really hard to fix the problem with so little information
        Hide
        Jaanus Heeringson added a comment -

        This is quite a complex project so I'll try as best as I can.
        What is happening here is that I'm adding another category (id:28) to the object (in this case an entry) that allready has one existing category (id: 10). The primary Id's are named - id!

        The Code
        	public function setJsonData($query,$data){
        		$_query=$this->primaryQuery($query,self::RELATIONS_FULL); //generates DQL query - not relevant
        		$_record=$_query->getOne(array(),2); //Fetches the existing record from DQL query
        		$data=$this->fromJsonData($data,$query); //Cleans up the recieved JSON data and returns an array
        		ss_error::log($data,'In data'); //Data output 1 - incoming data
        		ss_error::log($_record->toArray(),'Existing data'); //Data output 2 - record contents
        		$_record->synchronizeWithArray($data,true);//Synchronize
        		ss_error::log($_record->toArray(),'Merged data'); //Data output 3 - resulting datac
        		$_record->save(); //#ERROR#
        		return $_record->toArray(true);
        	}
        
        Data output 1 - incoming, cleaned up data
        array (
          'id' => '5',
          'active' => true,
          'timedpub' => true,
          'slug' => 'how_we_work',
          'date_pub' => NULL,
          'date_rej' => NULL,
          'UserCreate' => NULL,
          'UserModify' => NULL,
          'Category' => 
          array (
            0 => '10',
            1 => '28',
          ),
          'User' => 
          array (
          ),
          'Translation' => 
          array (
            'en' => 
            array (
              'headline' => 'How we work',
              'name' => 'how we work',
              'teaser' => NULL,
              'text' => '...',
              'lang' => 'en',
              'id' => '5',
            ),
            'sv' => 
            array (
              'headline' => 'Så arbetar vi',
              'name' => 'Så arbetar vi',
              'teaser' => '<br />',
              'text' => '...',
              'lang' => 'sv',
              'id' => '5',
            ),
          ),
          'user_create_id' => NULL,
          'user_modify_id' => NULL,
        )
        
        Data output 2 - record contents
        array (
          'id' => '5',
          'active' => true,
          'timedpub' => true,
          'slug' => 'how_we_work',
          'date_pub' => NULL,
          'date_rej' => NULL,
          'user_create_id' => NULL,
          'user_modify_id' => NULL,
          'created_at' => '2009-11-12 01:41:36',
          'updated_at' => '2009-11-12 01:41:36',
          'Category' => 
          array (
            0 => 
            array (
              'id' => '10',
              'slug' => 'arbetsmetod',
              'path' => '/om_hamilton/arbetsmetod',
              'parent_id' => NULL,
              'owner_id' => '8',
              'public' => true,
              'created_at' => '2009-11-12 01:41:38',
              'updated_at' => '2009-11-12 01:41:38',
              'Translation' => 
              array (
                'sv' => 
                array (
                  'id' => '10',
                  'name' => 'arbetsmetod',
                  'headline' => 'Vår arbetsmetod',
                  'lang' => 'sv',
                ),
              ),
            ),
          ),
          'User' => 
          array (
          ),
          'Translation' => 
          array (
            'en' => 
            array (
              'id' => '5',
              'headline' => 'How we work',
              'name' => 'how we work',
              'teaser' => NULL,
              'text' => '...',
              'lang' => 'en',
            ),
            'sv' => 
            array (
              'id' => '5',
              'headline' => 'Så arbetar vi',
              'name' => 'Så arbetar vi',
              'teaser' => '<br />',
              'text' => '...',
              'lang' => 'sv',
            ),
          ),
        )
        
        Data output 3 - result after Synchronize
        array (
          'id' => '5',
          'active' => true,
          'timedpub' => true,
          'slug' => 'how_we_work',
          'date_pub' => NULL,
          'date_rej' => NULL,
          'user_create_id' => NULL,
          'user_modify_id' => NULL,
          'created_at' => '2009-11-12 01:41:36',
          'updated_at' => '2009-11-12 01:41:36',
          'Category' => 
          array (
            0 => 
            array (
              'id' => '10',
              'slug' => 'arbetsmetod',
              'path' => '/om_hamilton/arbetsmetod',
              'parent_id' => NULL,
              'owner_id' => '8',
              'public' => true,
              'created_at' => '2009-11-12 01:41:38',
              'updated_at' => '2009-11-12 01:41:38',
              'Translation' => 
              array (
                'sv' => 
                array (
                  'id' => '10',
                  'name' => 'arbetsmetod',
                  'headline' => 'Vår arbetsmetod',
                  'lang' => 'sv',
                ),
              ),
            ),
            1 => 
            array (
              'id' => '28',
              'slug' => 'att_arbeta_hos_oss',
              'path' => '/karriar/arbeta_hos_oss',
              'parent_id' => NULL,
              'owner_id' => '21',
              'public' => true,
              'created_at' => '2009-11-12 01:41:39',
              'updated_at' => '2009-11-12 01:41:39',
            ),
          ),
          'User' => 
          array (
          ),
          'Translation' => 
          array (
            'en' => 
            array (
              'id' => '5',
              'headline' => 'How we work',
              'name' => 'how we work',
              'teaser' => NULL,
              'text' => '...',
              'lang' => 'en',
            ),
            'sv' => 
            array (
              'id' => '5',
              'headline' => 'Så arbetar vi',
              'name' => 'Så arbetar vi',
              'teaser' => '<br />',
              'text' => '...',
              'lang' => 'sv',
            ),
          ),
        )
        
        The error
        'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-10' for key 'PRIMARY''
        
        Show
        Jaanus Heeringson added a comment - This is quite a complex project so I'll try as best as I can. What is happening here is that I'm adding another category (id:28) to the object (in this case an entry) that allready has one existing category (id: 10). The primary Id's are named - id! The Code public function setJsonData($query,$data){ $_query=$ this ->primaryQuery($query,self::RELATIONS_FULL); //generates DQL query - not relevant $_record=$_query->getOne(array(),2); //Fetches the existing record from DQL query $data=$ this ->fromJsonData($data,$query); //Cleans up the recieved JSON data and returns an array ss_error::log($data,'In data'); //Data output 1 - incoming data ss_error::log($_record->toArray(),'Existing data'); //Data output 2 - record contents $_record->synchronizeWithArray($data, true ); //Synchronize ss_error::log($_record->toArray(),'Merged data'); //Data output 3 - resulting datac $_record->save(); //#ERROR# return $_record->toArray( true ); } Data output 1 - incoming, cleaned up data array ( 'id' => '5', 'active' => true , 'timedpub' => true , 'slug' => 'how_we_work', 'date_pub' => NULL, 'date_rej' => NULL, 'UserCreate' => NULL, 'UserModify' => NULL, 'Category' => array ( 0 => '10', 1 => '28', ), 'User' => array ( ), 'Translation' => array ( 'en' => array ( 'headline' => 'How we work', 'name' => 'how we work', 'teaser' => NULL, 'text' => '...', 'lang' => 'en', 'id' => '5', ), 'sv' => array ( 'headline' => 'Så arbetar vi', 'name' => 'Så arbetar vi', 'teaser' => '<br />', 'text' => '...', 'lang' => 'sv', 'id' => '5', ), ), 'user_create_id' => NULL, 'user_modify_id' => NULL, ) Data output 2 - record contents array ( 'id' => '5', 'active' => true , 'timedpub' => true , 'slug' => 'how_we_work', 'date_pub' => NULL, 'date_rej' => NULL, 'user_create_id' => NULL, 'user_modify_id' => NULL, 'created_at' => '2009-11-12 01:41:36', 'updated_at' => '2009-11-12 01:41:36', 'Category' => array ( 0 => array ( 'id' => '10', 'slug' => 'arbetsmetod', 'path' => '/om_hamilton/arbetsmetod', 'parent_id' => NULL, 'owner_id' => '8', ' public ' => true , 'created_at' => '2009-11-12 01:41:38', 'updated_at' => '2009-11-12 01:41:38', 'Translation' => array ( 'sv' => array ( 'id' => '10', 'name' => 'arbetsmetod', 'headline' => 'Vår arbetsmetod', 'lang' => 'sv', ), ), ), ), 'User' => array ( ), 'Translation' => array ( 'en' => array ( 'id' => '5', 'headline' => 'How we work', 'name' => 'how we work', 'teaser' => NULL, 'text' => '...', 'lang' => 'en', ), 'sv' => array ( 'id' => '5', 'headline' => 'Så arbetar vi', 'name' => 'Så arbetar vi', 'teaser' => '<br />', 'text' => '...', 'lang' => 'sv', ), ), ) Data output 3 - result after Synchronize array ( 'id' => '5', 'active' => true , 'timedpub' => true , 'slug' => 'how_we_work', 'date_pub' => NULL, 'date_rej' => NULL, 'user_create_id' => NULL, 'user_modify_id' => NULL, 'created_at' => '2009-11-12 01:41:36', 'updated_at' => '2009-11-12 01:41:36', 'Category' => array ( 0 => array ( 'id' => '10', 'slug' => 'arbetsmetod', 'path' => '/om_hamilton/arbetsmetod', 'parent_id' => NULL, 'owner_id' => '8', ' public ' => true , 'created_at' => '2009-11-12 01:41:38', 'updated_at' => '2009-11-12 01:41:38', 'Translation' => array ( 'sv' => array ( 'id' => '10', 'name' => 'arbetsmetod', 'headline' => 'Vår arbetsmetod', 'lang' => 'sv', ), ), ), 1 => array ( 'id' => '28', 'slug' => 'att_arbeta_hos_oss', 'path' => '/karriar/arbeta_hos_oss', 'parent_id' => NULL, 'owner_id' => '21', ' public ' => true , 'created_at' => '2009-11-12 01:41:39', 'updated_at' => '2009-11-12 01:41:39', ), ), 'User' => array ( ), 'Translation' => array ( 'en' => array ( 'id' => '5', 'headline' => 'How we work', 'name' => 'how we work', 'teaser' => NULL, 'text' => '...', 'lang' => 'en', ), 'sv' => array ( 'id' => '5', 'headline' => 'Så arbetar vi', 'name' => 'Så arbetar vi', 'teaser' => '<br />', 'text' => '...', 'lang' => 'sv', ), ), ) The error 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-10' for key 'PRIMARY''
        Hide
        Jonathan H. Wage added a comment -

        Is it possible for you to make an actual test case? That way I can just execute it and troubleshoot the problem very fast.

        Show
        Jonathan H. Wage added a comment - Is it possible for you to make an actual test case? That way I can just execute it and troubleshoot the problem very fast.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jaanus Heeringson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: