Application Layout
I am creating an application where you can create polls. Each survey has many questions. I am inserting questions into the survey model (with embeds_many in Mongoid), so the survey might look like this:
{ "id": "4f300a68115eed1ddf000004", "title": "Example Survey", "questions": [ { "id": "4f300a68115eed1ddf00000a", "title": "Please describe your experience with backbone.js", "type": "textarea" }, { "title": "Do you like it?", "id": "4f300a68115eed1ddf00000b", "type": "radiobutton", "options": ["Yes", "Yes, a lot!"] } ] }
Now there is also a survey editor, which consists of SurveyView , which displays the survey and lists the questions. If I click on one question, a QuestionView message will appear where I can edit the question. And when I'm happy with my poll and I click save, SurveyModel will be sent to the server.
Problem
What is the best way to handle inline association?
If I pass survey.get("questions")[any_index] to QuestionView and the question survey.get("questions")[any_index] , I will have to manually search for question.id in my model and update my model. This seems wrong.
If I create a QuestionsCollection in my SurveyModel (is this possible?). Then I can do things like extracting Question from this collection by id, passing it to the view and when I change the model everything will be updated automatically, but I have to specify the url in the collection and the spine will send separate questions to the server, if everything updated.
Is there any suggestion on how to do this on a trunk basis?