How to change Relationship from "Many-To-Many" to "One-To-Many"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theBuzzyCoder
    Senior Member
    • Feb 2018
    • 102

    How to change Relationship from "Many-To-Many" to "One-To-Many"?

    Hi tanya

    Right now Contact and Opportunity Relationship is "Many - to - Many" which is default.

    My use case needs it to be "One - to - Many".

    Please help
  • theBuzzyCoder
    Senior Member
    • Feb 2018
    • 102

    #2
    And how do I disable the default relationships completely. Like contact and opportunity relationship is there, right? I want to disable it completely.

    Comment

    • theBuzzyCoder
      Senior Member
      • Feb 2018
      • 102

      #3
      I have figured it out!

      Add "skipOrmDefs": true to disable the existing relationship in entityDefs/Opportunity.json

      Then add new relationship like below. In my use case, I had to make contact to opportunity one-to-many relation

      Code:
      {
          "fields": {
              "contacts": {
                  "skipOrmDefs": true,
                  "disabled": true,
                  "customizationDisabled": true,
                  "type": "linkMultiple",
                  "view": "crm:views/opportunity/fields/contacts",
                  "columns": {
                      "role": "opportunityRole"
                  },
                  "orderBy": "name",
                  "notStorable": true
              },
              "contact": {
                  "type": "link"
              }
          },
          "links": {
              "contacts": {
                  "type": "hasMany",
                  "entity": "Contact",
                  "foreign": "opportunities",
                  "layoutRelationshipsDisabled": true,
                  "additionalColumns": {
                      "role": {
                          "type": "varchar",
                          "len": 50
                      }
                  },
                  "skipOrmDefs": true
              },
              "contact": {
                  "type": "belongsTo",
                  "foreign": "opportunities",
                  "entity": "Contact",
                  "audited": true,
                  "isCustom": true
              }
          }
      }

      skipOrmDefs will stop from creating many-many map table or fields in database level
      disabled will disable field from displaying at layouts
      customizationDisabled will disable field from displaying at entity manager.
      Last edited by theBuzzyCoder; 11-24-2018, 11:26 AM.

      Comment

      Working...