Best practices to enforce 1:1 relationships?

It turns out that Sugar does not enforce 1:1 relationships, it overwrites them with no warning to the user. (Bug?)

Is my only option for enforcement a custom before-relationship-add logic hook?

Thanks,

Francesca

Parents
  • Hi ,

    The first answer comes to my mind is the logic hook as you mentioned. However, It would be good to know your use case. 

    Tevfik Tümer
    Sr. Developer Support Engineer 

  • Thank you  ,

    we have a 1:1 between Quotes and Cases.

    Cases are created to let our CS team know that the order is ready to enter.

    Our Sales team creates a Case to process an Order in our ERP system for a given a Quote, and attaches the customer PO to the Case, they link the Case to the Quote.

    We want to make sure that there is only one Case per Quote and only one Quote per Case, and if someone tries to enter a second Case for that same quote, or a second Quote for the same Case, we want to stop them from doing so and alert them to the fact that there is already a Case for that Quote.

    I added a 1:1 Cases-Quotes.

    Example of the non enforcement:

    CaseA, relate to QuoteA => The related CaseA shows on the QuoteA, the related QuoteA shows on the CaseA

    CaseB relate to QuoteA => CaseB shows QuoteA, QuoteA shows CaseB, CaseA has lost the relationship and is left without a related Quote and there was no warning that the relationship between CaseA and QuoteA was being removed.

    To me, that's a big problem as other Sugar customers in similar scenarios may be losing data.
    The logical expectation of a 1:1 is that it would be enforced by the code with a warning that proceeding will destroy the previously exising relationship.

    Thank you,

    Francesca

  • Thanks for the details.

    Honestly, I would consider this problem from different aspects.

    If the main concern is preventing this from happening in the UI, then I would work on the related field.

    Users are probably clicking the related field and selecting from the list view. You can force that list view to avoid listing the quotes that have cases. Using filters should also affect typeahead queries.

    As a preventive measure, you could throw an exception before saving if the fetched row already has that field. Since they are 1-1, you should be able to check that as a field rather than a relationship.

    Tevfik Tümer
    Sr. Developer Support Engineer 

Reply
  • Thanks for the details.

    Honestly, I would consider this problem from different aspects.

    If the main concern is preventing this from happening in the UI, then I would work on the related field.

    Users are probably clicking the related field and selecting from the list view. You can force that list view to avoid listing the quotes that have cases. Using filters should also affect typeahead queries.

    As a preventive measure, you could throw an exception before saving if the fetched row already has that field. Since they are 1-1, you should be able to check that as a field rather than a relationship.

    Tevfik Tümer
    Sr. Developer Support Engineer 

Children
No Data