Aaccess records through Many to Many relation.

Hi,

I use the default Many-to-Many relation between the Contacts module and the Documents module to store documents related with each contact records. I need to access documents related to a particular Contact record through REST api code. I use Ruby sugarcrm gem for this. I could access One-to-one an one-to-many relations easily. But could not access Many-to-Many relations. Somebody please help me in this either through gem or through REST v10 code. I will be happy if i could get id of documents related with Contacts.

Thanks in advance,

-sudeep.

  • Hi Sudeep,

    Asking out of curiosity, how are you going to use the files/documents? Because we have How to Manipulate File Attachments / Getting a File Attachment  documentation shows that how to download a document.

    Simply you need to have the document record id and field name and make a get call. In example;

    http://{site_url}/rest/v10/MODULE(Documents)/RECORD_ID/file/your_document_field


    So if i sum up my possible solution i would make a one call which would retrieve all the documents related to a contacts.

    1. Using How to Fetch Related Records / Fetching Related Records i would retrieve all documents related to contacts. It is working for one to many and many to many relationships.

      http://{site_url}/rest/v10/Contacts/CONTACT_ID/link/documents

    2. Then build the download links using the document ids like;

      http://{site_url}/rest/v10/MODULE(Documents)/RECORD_ID/file/your_document_field

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik Tümer,

    Thank you so much for your response. It worked for me. I could access document ids, now I can build the code to download. Actually I am new to the REST v10 api of sugar. I used to work with the Ruby gem, which used REST v2. Thank you once again.

    - sudeep

  • Hi Sudeep,

    I'm glad it works for you.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer