Hi all,
the following problem occurs:
//add new relationship
$bean->load_relationship('test1_test2');
$bean->test1_test2->add($new_bean);
//edit value
$bean->value1 = "val1";
//value1 saved, but relationship is lost
$bean->save();
Hi all,
the following problem occurs:
//add new relationship
$bean->load_relationship('test1_test2');
$bean->test1_test2->add($new_bean);
//edit value
$bean->value1 = "val1";
//value1 saved, but relationship is lost
$bean->save();
What is the context? Where is that running? Which module, which hook, etc.
This is part of the custom api. For the test, I use the modules created in the modulebuilder
Check that load_relationship returns true.
yes, load_relationship returns true and add returns true
I think the bean contains links to the previous link and when saved they overwrite the new links. Is there any way to update the links in the current bean or not touch the links at all when saving?
give an example in more detail
$link = BeanFactory::getBean('test_mylinks', '53bdc89e-8dbe-53ae-278a-62d656e804b9');
$bean = BeanFactory::getBean('test_mybeans', '7a95a4f6-cab3-0931-3a43-62d65d22be6e');
$bean->description = 'The bean now have relationship';
$bean->save();
$bean->load_relationship('test_mybeans_test_mylinks');
$bean->test_mybeans_test_mylinks->add($link);
//The bean now have relationship and description
$bean = BeanFactory::getBean('test_mybeans', '7a95a4f6-cab3-0931-3a43-62d65d22be6e');
$bean->load_relationship('test_mybeans_test_mylinks');
$bean->test_mybeans_test_mylinks->delete($bean);
$bean->description = 'Has the link been removed?';
$bean->save();
//No, the relationship remains, only the description has changed
Looking in the code of the save function, I found the mention of the variables
$GLOBALS['updating_relationships']
$GLOBALS['saving_relationships']
$GLOBALS['resavingRelatedBeans']
When using updating_relationships, links are updated correctly. Are they intended for these purposes or did it indirectly correct the logic?
This command doesn’t look right, you’re using $bean twice
I don’t know about those GLOBALS you mention, I don’t think they are relevant here.