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.