Not sure if this was overlooked or a feature but at the moment i can't see nothing stopping taxonomy removing a relationship on term_save, as taxonomy removes the relationship and then re-inserts it and that's the problem because there is no relationship to re-insert.

I am experiencing the above mentioned bug at the moment.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

droid19’s picture

Assigned: Unassigned » droid19
Status: Active » Needs review
FileSize
1.47 KB

I've created a patch which has seemed to fix the issue for me. Kinda new to patching so if the file is not of the correct format feel free to update.

Also you need to use the attached install file to create the new table which will cache and restore the relationships.
Looks like I can't attach .install files, so either create the table yourself or copy and paste the following into a .install file:

<?php
function taxonomy_vocab_relate_schema(){
$schema['term_relation_cache'] = array(
  'description' => t('TODO: please describe this table!'),
  'fields' => array(
    'tid1' => array(
      'description' => t('TODO: please describe this field!'),
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ),
    'tid2' => array(
      'description' => t('TODO: please describe this field!'),
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ),
  ),
);
	
	return $schema;
}

function taxonomy_vocab_relate_update_6100(){
	drupal_install_schema('taxonomy_vocab_relate');
	return array();
}
andrew.lansdowne’s picture

I have had the same problem:

Say you have a parent vocab and child, where the child is set to be related to the parent, then you add terms to the child and set relations up to the parent one. Then if you edit the parent term and save, it deletes all the child->parent relations for that parent term.

A workaround I have found is to set the vocab relate on both taxonomies. So parent is related to child and child is related to parent. Then when you edit a term in parent there is a 'related terms in child' with all of them ticked, and it doesn't loose any.

If that is not an option then your fix seems like the only way to fix it (haven't tried it though).

BrockBoland’s picture

Assigned: droid19 » BrockBoland
FileSize
2.16 KB

I'm seeing this same problem. It's caused by taxonomy_save_term(), which deletes any relationship that includes the term being edited, then re-saves the relationships from the form. In normal usage, this is fine, because a relationship with terms in the same vocabulary would remain selected in the multi-select box.

I would like to propose a different solution, though. I wanted to avoid adding the DB overhead and an extra table, so I implemented a fix that only requires changes to existing functions in the module.

This patch adds to the taxonomy_vocab_relate_form_alter() function. It will now load up "opposing" relations - those where a term in another vocabulary has a relationship to the term being edited. These are stored in an array in the $form array, so that they are available in taxonomy_vocab_relate_term_submit(), where they are re-saved.

Coupon Code Swap’s picture

I tried the patch and it is causing duplicate relationships.

BrockBoland’s picture

undoIT: Have you applied any other patches from this module's issues? Which version of Drupal core are you running? Could you try saving from both directions - save the term that has a relationship to the other term, and save the term that has a relation from another term?

andrew.lansdowne’s picture

This also happens when you re-order terms in the List Terms page. It loses relations and synonyms. It is a long-standing bug in core, since if you use the core functionality to add related terms within the same vocab and then reorder those terms, the relations are also lost! Link to core issue: http://drupal.org/node/251255

The patch from #57 in the link above seems to work for Drupal 6 to keep term relations when you re-order. Contributed modules which call taxonomy_save_term may still cause it to lose all the relations (and synonyms).

To fix the issue in this thread you still need to either enable relationship both ways, or apply one of the patches. I suggest you apply the core patch as well to avoid losing relations when you order terms.