Custom filter for many-to-many relationships

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fberbert
    Junior Member
    • Dec 2024
    • 10

    #1

    Custom filter for many-to-many relationships

    I have a custom filter (select-related) that actually WORKS:

    Code:
    const filterObject = {
       advanced: {
          myFilter: {
             type: 'equals',
             attribute: 'accountId',
             value: accountId
          }
       }
    };
    The code above filters a specific field of the Contacts entity (`accountId`) by the provided value.

    However, I created a many-to-many relationship where multiple Contacts can belong to multiple Accounts. The relationship's name is `accounts`. I want the filter to work for any contact whose `accountId` is present in the `accounts` relationship (link multiple).

    Code:
    const filterObject = {
       advanced: {
          myFilter: {
             type: 'equals',
             link: 'accounts',
             attribute: 'id',
             value: accountId
          }
       }
    };

    The syntax above is, of course, incorrect; it’s just my draft. Would anyone be able to tell me what the correct syntax should be? I couldn't find anything in the documentation or online.
  • fberbert
    Junior Member
    • Dec 2024
    • 10

    #2
    I managed to resolve it; here's the solution...

    In the type, I used linkedWith, in the attribute, I used the name of the link, and in the value, I used brackets because it comes in the form of a list.

    Code:
    {
    type: 'linkedWith',
    attribute: 'accounts',
    value: [accountId]
    }

    Comment

    Working...