Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

SS3 + RESTFulserver: Create / View many_many relations




4 October 2013 at 7:33am (Last edited: 7 October 2013 10:25pm), Community Member, 8 Posts

I am writing a Javascript Application that uses SS3 (Sapphire only) and the [url=]RESTFulServer module[/url] as a backbone to view/edit/create/delete multiple DataObjects (no backbone.js application!).
Everything works fine for simple DataObjects. Normal fields, has_one and has_many relations do work pretty well. (saving, reading, deleting, updating)

Now I implemented a new DataObject with a many_many relation to an existing DataObject. The existing DataObject also has the new one as a belongs_many_many relation.

I am able to create and read this new DataObject via the RESTFul API. But when creating a new one, my many_many relations are not written into the many_many table. And when I add the many_many relation to $api_access, I get an error when trying to view the DataObjects via REST:

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'ManyManyList'

The $api_access on the new DataObject looks something like this: ("TimeTrackValues" is the many_many relation)

$api_access = array("Title", "ID", "Created", "MemberID", "TimeTrackValues")

The related DataObjects all have a canView function and are creatable/readable via the RESTFulServer. The only thing that doesnt work is the many_many relation.

Also I am not sure about, how to POST the `TimeTrackValues` ID Array..
My current implementation creates the following "POST Form" request Data in my Webinspector:

Title:my Title

Comma separating, does not work ( TimeTrackValues:45,46,47 ).

I hope you guys understand what my problem is.
Sadly I couldn't find a documentation on the RestfulServer module that covers many_many relations. Maybe there is one I didn't find?

Thank you very much, I am thankful for any kind of help!


For anyone who might be interested, I found a solution by sending the ID's with a custom property (e.g. 'MyIDs'), catching them up in an onAfterWrite() hook and then adding them manually.