Search code examples
sugarcrmsuitecrm

Cannot see past relationships in before_relationship_add hook


For some reason when executing $bean->relation->getBeans() inside before_relationship_add hook it shows old AND new relationship.

I just want to see the relationships that were there BEFORE..

I tried to extract it from $bean and $arguments, but can't seem to find it


Solution

  • We can see what new record was added by checking $arguments['related_module'] and $arguments['related_id'].

    So if we can identify what is the new record, we can determine what the old records were there prior to relationship add..

    Example: we have 3 records with IDs 1,2 and 3 and the latest ID that was added is 3 ($arguments['related_id']), that means that IDs 1 and 2 were there before relationship was added.

    This is kind of backwards and was hoping that before_relationship_ad

    Technically speaking we can even do this in the after_relationship_add hook