Bidrectional relationship between Contacts and Accounts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SoBeGuy
    Member
    • Jan 2024
    • 62

    Bidrectional relationship between Contacts and Accounts

    In Espo, the Contacts entity has a many/many relationship with the Accounts entity. However, I'm observing some strange behavior:
    1. If I add an account to a contact, the account appears on the contact's screen and the contact automatically appears on the account's screen. This is expected and fine.
    2. If I add a contact to an account, the contact appears on the account's screen and the account automatically appears on the contact's screen. Also expected and fine.
    3. If I remove an account from a contact, the contact is also removed from the account. Expected and fine.
    4. If I remove a contact from an account, the account is NOT removed from the contact. This is unexpected and NOT fine.
    I'm pretty sure this is happening because of the account_id field in the contact entity. This field stores the primary account ID independently from the many/many relationship managed by the account_contact table. So when you remove a contact in the account's screen, it removes it from the many/many relationship, but it's still in the contacts entity. Is there any way to remove that account_id field and the relationship? The idea of having a separate field for primary account doesn't seem like good design, as it's redundant and confusing. If anything, there should be a "primary" field in the account_contact table.
  • esforim
    Active Community Member
    • Jan 2020
    • 2204

    #2
    I don't quite agree with Number 4. You can do a formula/workflow to delete Account record if Contact if empty if you want to do this.

    I have Account with 0 Contact, personally we use Account as a Grouping, for example: Company, Family, Group, etc. I would not want to delete 1 record and another record is automatic deleted.

    Comment

    • SoBeGuy
      Member
      • Jan 2024
      • 62

      #3
      Originally posted by espcrm
      I don't quite agree with Number 4. You can do a formula/workflow to delete Account record if Contact if empty if you want to do this.

      I have Account with 0 Contact, personally we use Account as a Grouping, for example: Company, Family, Group, etc. I would not want to delete 1 record and another record is automatic deleted.
      esforim You misunderstood my point entirely. I never said anything about deleting records. I'm talking about links between accounts and contacts. If you add a contact to an account, that creates a bidirectional link. So if you open the contact, the account shows up in the list of accounts. If you open the account, the contact shows up in the list of contacts. The problem is, if you remove a contact from an account, as described in #4, then open the contact record, the account still appears in the contact's list of accounts. This doesn't seem correct. When you remove a bidirectional link, it should be removed from both the contact record and the account record.

      Comment

      • esforim
        Active Community Member
        • Jan 2020
        • 2204

        #4

        My apology, I think I get what you saying now. But for me the Account<>Contact does get delete. Let me know if I'm still not comprehending.

        Here is my before
        Click image for larger version

Name:	image.png
Views:	118
Size:	16.8 KB
ID:	105841
        Click image for larger version

Name:	image.png
Views:	105
Size:	9.7 KB
ID:	105842
        Click image for larger version

Name:	image.png
Views:	96
Size:	5.0 KB
ID:	105843

        And after I click Unlink
        Click image for larger version

Name:	image.png
Views:	99
Size:	6.0 KB
ID:	105844

        Comment

        • victor
          Active Community Member
          • Aug 2022
          • 728

          #5
          SoBeGuy,

          Maybe you confused the account and the accounts fields, which are created using different relationships (screenshot 1, 2 and 3)?

          If not, please send screenshots or a link to a video where you reproduce the steps you described.​
          Attached Files

          Comment

          Working...